sla*_*dan 5 sql sql-server boolean
在我的 SQL Server 查询中,我希望始终获得 0 个结果。我只想获取元数据。
如何在 TSql 中编写始终错误的评估?是否有内置函数或推荐的方法?
目前我使用WHERE 1 = 0,但我正在寻找类似的东西WHERE 'false'。
虽然您可以用于where 1 = 0此目的,但我认为top 0更常见:
select top 0 . . .
. . .
Run Code Online (Sandbox Code Playgroud)
这也防止了该条款中的“意外” where。如果你改变这个:
where condition x or condition y
Run Code Online (Sandbox Code Playgroud)
到:
where 1 = 0 and condition x or condition y
Run Code Online (Sandbox Code Playgroud)
括号是错误的。