Conditional Operator in SQL Where Clause

前端 未结 5 2048
我寻月下人不归
我寻月下人不归 2020-12-20 16:47

I\'m wishing I could do something like the following in SQl Server 2005 (which I know isnt valid) for my where clause. Sometimes @teamID (passed into a stored procedure) wi

5条回答
  •  眼角桃花
    2020-12-20 17:07

    You can do that without a case:

    SELECT  Team.teamID 
    FROM    Team
    WHERE   (@teamid = 0 AND Team.teamID > 0)
            OR (@teamid <> 0 AND Team.teamID = @teamid)
    

提交回复
热议问题