'Mod' Is Not a Recognized Built-in Function Name

'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?

0

5 Answers

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

Use % instead.

Ref: Modulo

3

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

SELECT 38 % 5 would give you the modulo 3

0

for your exact sample, it should be like this.

DECLARE @m INT
SET @m = 321%11
SELECT @m
0

It can be done using % operator. i.e. SELECT 50 % 5

If using JDBC driver you may use function escape sequence like this:

select {fn MOD(5, 2)}
#Result 1

select  mod(5, 2)
#SQL Error [195] [S00010]: 'mod' is not a recognized built-in function name.
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.