T-SQL中有三元运算符吗?
或者有什么替代scheme来实现下一个查询:
select * from table where isExternal = @type = 2 ? 1 : 0`
用case :
select * from table where isExternal = case @type when 2 then 1 else 0 end
在SQL Server 2012中 ,您可以使用IIF函数 :
SELECT * FROM table WHERE isExternal = IIF(@type = 2, 1, 0)
另请注意:在T-SQL中,赋值(和比较)运算符只是= (而不是== – 这就是C#)