'MOD' is not a recognized built-in function name
114,444
Solution 1
The MOD
keyword only exists in the DAX
language (tabular dimensional queries), not TSQL
Use %
instead.
Ref: Modulo
Solution 2
In TSQL, the modulo is done with a percent sign.
SELECT 38 % 5 would give you the modulo 3
Solution 3
for your exact sample, it should be like this.
DECLARE @m INT
SET @m = 321%11
SELECT @m
Author by
hoggar
Updated on July 09, 2022Comments
-
hoggar almost 2 years
I wanted to use
MOD
function inSQL 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?
-
Saurin Vala about 8 yearsLife saving ans. thnx
-
openwonk almost 8 years
MOD
also works in Informix syntax... For all those back in the 1990s! -
Amirhossein over 4 yearsis not the answer of question , MOD Returns the remainder after a number is divided by a divisor. The result always has the same sign as the divisor.
-
Ramin Melikov about 4 yearsIt's kind of upsetting that SQL Server is not ANSI compliant, though. I want to be able to write a SQL query that will work everywhere. Oracle uses MOD(), MySQL uses MOD() and %, Microsoft Uses %. Ridiculous.