How to use ternary operator in SQL Server 2008?
sql, sql-server
Solution
This is for SQL Server. `IIF` is not available in SQL Server 2008 or earlier.
SELECT *
FROM Account
WHERE
Id=IIF(type<> 100000002,"something",null )
If you are using SQL Server 2008 or earlier, then try this.
SELECT *
FROM Account
WHERE (Id= CASE WHEN type <>100000002 THEN 'something' ELSE null END)
Problem
SQL query: ``` SELECT * FROM Account WHERE (type <>100000002 ? Id='something': Id=null) ``` but it shows error : Incorrect syntax near '?' Please help me.