SQL “MOD”不是可识别的内置函数名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23310661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:44:41  来源:igfitidea点击:

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

sqlsql-server-2008tsqlsql-server-2008-r2modulo

提问by hoggar

I wanted to use MODfunction in SQL Server 2008R2and followed this linkbut still got the message:

我想在中使用MOD函数SQL Server 2008R2并点击此链接,但仍然收到消息:

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

'MOD' 不是可识别的内置函数名称。

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.

消息 195,级别 15,状态 10,第 2 行
“MOD”不是可识别的内置函数名称。

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

为什么我不能从上面的链接使用这个功能?

回答by Mitch Wheat

The MODkeyword only exists in the DAXlanguage (tabular dimensional queries), not TSQL

MOD关键字只有在存在DAX语言(表格维度查询),不TSQL

Use %instead.

使用 %来代替。

Ref: Modulo

参考:模数

回答by Karl Kruse

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

在 TSQL 中,模数是用百分号完成的。

SELECT 38 % 5 would give you the modulo 3

SELECT 38 % 5 会给你模 3

回答by Anura Adhikari

for your exact sample, it should be like this.

对于您的确切样本,它应该是这样的。

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

回答by Malik Hassan Qayyum

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

可以使用 % 运算符来完成。即选择 50 % 5

回答by Qamar Al Zaman Habeek

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

如果使用 JDBC 驱动程序,您可以使用这样的函数转义序列:

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

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