Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can this SQL CASE WHEN statement be made shorter?

Are there any features within Microsoft SQL Server TSQL that could shorten this CASE WHEN statement?

   CASE 
         WHEN some_column IS NULL 
         THEN 0
         ELSE 1
   END
like image 768
Preet Sangha Avatar asked Dec 29 '25 14:12

Preet Sangha


1 Answers

For SQL Server 2012 and later you can use IIF() statement.

SELECT IIF(some_column IS NULL , 0 , 1)
like image 188
M.Ali Avatar answered Jan 01 '26 05:01

M.Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!