Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'MOD' is not a recognized built-in function name

I wanted to use MOD function in SQL Server 2008R2 and followed this link but still got the message:

'MOD' is not a recognized built-in function name.

DECLARE @m INT SET @m = MOD(321,11) SELECT @m 

Error:

Msg 195, Level 15, State 10, Line 2
'MOD' is not a recognized built-in function name.

Why I can't use this function from the link above?

like image 693
hoggar Avatar asked Apr 26 '14 12:04

hoggar


People also ask

What is MOD function in SQL Server?

SQL MOD() function is used to get the remainder from a division. The SQL DISTINCT command along with the SQL MOD() function is used to retrieve only unique records depending on the specified column or expression. Syntax: MOD( dividend, divider ) PostgreSQL and Oracle.

What is MOD function in Oracle?

The Oracle MOD() is used to return the remainder of a dividend divided by a divisor. This function also works on fractional values and returns the exact remainder. The function returns dividend when the value of divisor is 0.

What does abs do in SQL?

A mathematical function that returns the absolute (positive) value of the specified numeric expression. ( ABS changes negative values to positive values. ABS has no effect on zero or positive values.)

How do you find the quotient in SQL?

DIV() Function in MySQL This function in MySQL is used to return a quotient (integer) value when integer division is done. For example, when 7 is divided by 3, then 2 will be returned.


2 Answers

The MOD keyword only exists in the DAX language (tabular dimensional queries), not TSQL

Use % instead.

Ref: Modulo

like image 119
Mitch Wheat Avatar answered Oct 05 '22 16:10

Mitch Wheat


In TSQL, the modulo is done with a percent sign.

SELECT 38 % 5 would give you the modulo 3

like image 36
Karl Kruse Avatar answered Oct 05 '22 16:10

Karl Kruse