mysql - sql server 中 where 子句中的 case 语句与 else 始终为真

标签 mysql sql sql-server tsql case

我使用了永远正确的陈述,例如1 = 1在MYSQL中where子句的case语句,语法如下:

select * from tablename where 
(case when tablefield is not null then 
 then tablefield = 'value'
else 1 = 1 end)

我想知道如何在 sqlserver/tsql case 语句的 where 子句中使用 else 1 = 1(始终为 true 语句)。

最佳答案

你不会使用 case 你只会写一个多条件语句。在你的情况下它看起来像

Where (tablefield = 'value'
       OR tablefield is null)

关于mysql - sql server 中 where 子句中的 case 语句与 else 始终为真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28865989/

相关文章:

mysql - 计数查询的未知列

mysql - 获取结果的sql查询

mysql - join sql查询中where和and子句的区别

sql-server - Powershell x86 : Could not load file or assembly Microsoft. SqlServer.BatchParser

mysql - CSV 导入和使用 LOAD DATA 的 CSV 之间的区别?

php - UTF-8贯穿始终

php - 无法在我的导航栏的下拉菜单中传递 id

sql - 查找与经理住在同一城市和街道的所有员工

sql - 如何从 cfquery 检索 SQL 变量?

sql-server - 是否可以从 SQL Server 列出 TFS 组中的所有用户