programing

T-SQL에 3진수 조건 연산자가 있나요?

starjava 2023. 4. 17. 21:13
반응형

T-SQL에 3진수 조건 연산자가 있나요?

다음 쿼리를 구현하기 위한 대체 방법은 무엇입니까?

select *  
from table  
where isExternal = @type = 2 ? 1 : 0

SQL Server 2012에서는 다음 기능을 사용할 수 있습니다.

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

주의: T-SQL에서 할당(및 비교) 연산자는=(그리고 아니다)==- C#입니다.)

사용하다case:

select *
from table
where isExternal = case @type when 2 then 1 else 0 end

언급URL : https://stackoverflow.com/questions/16209751/is-there-a-ternary-conditional-operator-in-t-sql

반응형