0

我尝试在 SQL Server 中执行此查询:

select * from users where case when 1=1 then name is null else true end;

但我得到了这个错误:

关键字“is”附近的语法不正确

此查询在 MySQL 中成功运行。你能告诉我这个查询在 SQL Server 中的等价物吗?

4

1 回答 1

2

你不能做这样的表达,语法是错误的。

如果要选择条件,则必须使用逻辑运算符:

where (1=1 and name is null)
   or (1<>1 and 1=1)

我替换true为始终评估为 true ( 1=1) 的条件,因为true它本身是查询中的另一个语法错误。

于 2019-10-30T06:39:44.423 回答