[sql] '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?

This question is related to sql sql-server-2008 tsql sql-server-2008-r2 modulo

The answer is


for your exact sample, it should be like this.

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

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.

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

SELECT 38 % 5 would give you the modulo 3


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


Examples related to sql

Passing multiple values for same variable in stored procedure SQL permissions for roles Generic XSLT Search and Replace template Access And/Or exclusions Pyspark: Filter dataframe based on multiple conditions Subtracting 1 day from a timestamp date PYODBC--Data source name not found and no default driver specified select rows in sql with latest date for each ID repeated multiple times ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database

Examples related to sql-server-2008

Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object How to Use Multiple Columns in Partition By And Ensure No Duplicate Row is Returned SQL Server : How to test if a string has only digit characters Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query Get last 30 day records from today date in SQL Server How to subtract 30 days from the current date using SQL Server Calculate time difference in minutes in SQL Server SQL Connection Error: System.Data.SqlClient.SqlException (0x80131904) SQL Server Service not available in service list after installation of SQL Server Management Studio How to delete large data of table in SQL without log?

Examples related to tsql

Passing multiple values for same variable in stored procedure Count the Number of Tables in a SQL Server Database Change Date Format(DD/MM/YYYY) in SQL SELECT Statement Stored procedure with default parameters Format number as percent in MS SQL Server EXEC sp_executesql with multiple parameters SQL Server after update trigger How to compare datetime with only date in SQL Server Text was truncated or one or more characters had no match in the target code page including the primary key in an unpivot Printing integer variable and string on same line in SQL

Examples related to sql-server-2008-r2

A connection was successfully established with the server, but then an error occurred during the login process. (Error Number: 233) Rebuild all indexes in a Database How to get last 7 days data from current datetime to last 7 days in sql server Get last 30 day records from today date in SQL Server what is numeric(18, 0) in sql server 2008 r2 Conversion failed when converting date and/or time from character string in SQL SERVER 2008 'MOD' is not a recognized built-in function name How to Convert datetime value to yyyymmddhhmmss in SQL server? SQL Server stored procedure Nullable parameter SQL Server 2008 R2 can't connect to local database in Management Studio

Examples related to modulo

'MOD' is not a recognized built-in function name Modulo operation with negative numbers Can't use modulus on doubles? Assembly Language - How to do Modulo? How to use mod operator in bash? How can I calculate divide and modulo for integers in C#? What is the result of % in Python? How does java do modulus calculations with negative numbers? Integer division with remainder in JavaScript? How to code a modulo (%) operator in C/C++/Obj-C that handles negative numbers