Is there a ternary conditional operator in T-SQL?

后端 未结 2 1804
青春惊慌失措
青春惊慌失措 2021-01-30 01:25

What are alternatives to implement the following query:

select *  
from table  
where isExternal = @type = 2 ? 1 : 0
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 01:47

    In SQL Server 2012, you could use the IIF function:

    SELECT *
    FROM table
    WHERE isExternal = IIF(@type = 2, 1, 0)
    

    Also note: in T-SQL, the assignment (and comparison) operator is just = (and not == - that's C#)

提交回复
热议问题