sqlserver中的case语句在where子句中,else始终为true

kur*_*urm 1 mysql sql t-sql sql-server case

我使用了始终为true的语句,例如1 = 1在MYSQL中使用where语句的case语句,语法如下:

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

我想知道如何1 = 1在where子句中的sqlserver/tsql case语句中使用else (always true statement).

小智 6

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

Where (tablefield = 'value'
       OR tablefield is null)
Run Code Online (Sandbox Code Playgroud)