Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write IF(expr1,expr2,expr3) in mssql

There is IF(expr1,expr2,expr3) in my sql.

How to accomplish it in MS SQL?

like image 981
SpoksST Avatar asked Dec 29 '22 04:12

SpoksST


1 Answers

You can use a CASE expression:

CASE WHEN expr1 THEN expr2 ELSE expr3 END

By the way, this syntax isn't SQL Server specific - it also works in MySQL and most other databases.

like image 200
Mark Byers Avatar answered Jan 18 '23 10:01

Mark Byers