IF ELSE Statement in SQL

后端 未结 7 506
名媛妹妹
名媛妹妹 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 13:04

    Don't quite understand, but if you mean the input variables equal zero, you could do something like:

    SELECT S.Id, S.Name, S.Version, S.SoftNo
    FROM SOFTWARE S WITH(NOLOCK)
    WHERE ((@Version = 0 AND S.Version > 0) OR (S.Version = @Version AND @Version > 0))
    AND (@SoftNo = 0 AND S.SoftNo > 0) OR (@SoftNo = S.SoftNo AND @SoftNo > 0 )
    
    0 讨论(0)
提交回复
热议问题