How do I use a comma separated list of values as a filter in T-SQL?

后端 未结 10 1695
無奈伤痛
無奈伤痛 2021-02-09 14:03

I have a basic SQL query, starting with:

SELECT top 20 application_id, [name], location_id FROM apps

Now, I would like to finish it so that it

10条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-09 14:27

    While it is not exactly a best practice to use 1=1, it does the trick here.

    SELECT top 20 application_id, [name], location_id FROM apps
    WHERE
      (@lid > 0 and @lid = location_id)
    or
      (isnull(@lid, 0) <= 0 and 1=1)
    

提交回复
热议问题