今天完全是偶然的,我运行了一个 SQL 语句来按日期过滤一些项目,为了简单起见,我们会说我使用了
SELECT *
FROM [TableName]
WHERE [RecordCreated] >+ '2016-04-10'
只有在语句运行后,我才意识到我使用了 >+ 而不是 >=,现在我很困惑,因为我预期会出现错误。
我尝试了一些其他变体,例如
>- -- Throws an error
<+ -- Ran successfully
<- -- Throws an error
无论我使用 >= 还是 >+,返回的行数都完全相同
在网上搜索后,我找不到任何直接涵盖此语法的文档,只有当这两个运算符分开使用时。
RecordCreated
列是 datetime
.对于可能的常见错误,这只是语法上的一个细节,还是可能试图将日期转换为数值?
最佳答案
这似乎是“+”运算符的错误。
根据微软团队的更新,
After some investigation, this behavior is by design since + is an unary operator. So the parser accepts "+ , and the '+' is simply ignored in this case. Changing this behavior has lot of backward compatibility implications so we don't intend to change it & the fix will introduce unnecessary changes for application code.
您可以通过 RGO 找到一个非常好的答案。到他自己的问题 here .
关于sql-server - 运算符 >+ 与 SQL Server 2012 中的 >= 有何不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36716272/