IF ELSE Statement in SQL

后端 未结 7 508
名媛妹妹
名媛妹妹 2021-01-22 12:10
SELECT S.Id, S.Name, S.Version, S.SoftNo
FROM SOFTWARE S WITH(NOLOCK)
WHERE (IF S.Version = 0 THEN S.Version > 0 ELSE S.Version = @Version)
AND (IF S.SoftNo = 0 THEN          


        
7条回答
  •  再見小時候
    2021-01-22 12:41

    Have you thought of using SQL cases?

    SELECT col1, col2,
        CASE
            WHEN expression THEN return 
            WHEN expression THEN return 
            ELSE return 
        END AS NameOfNewColWithReturnValues
    FROM Col_FROM_WHICH_TABLE 
    

提交回复
热议问题