CASE in WHERE, SQL Server

前端 未结 5 1843
南笙
南笙 2020-12-06 04:47

I\'m doing some search, where users are choosing in dropdown some clauses. When they leave some box empty, I want query to ignore clause. I know CASE, and best I thought of

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 05:11

    Try this:

    WHERE a.Country = (CASE WHEN @Country > 0 THEN @Country ELSE a.Country END)
    

提交回复
热议问题