Can a stored procedure have dynamic parameters to be used in an “IN” clause?

前端 未结 6 1221
闹比i
闹比i 2020-12-06 03:29

I want to run a query like this:

 SELECT * FROM Studio WHERE Id IN (134, 144, 132, 138, 7432, 7543, 2566)

but the amount of Id<

6条回答
  •  没有蜡笔的小新
    2020-12-06 03:54

    You can absolutely do this in a stored procedure.

    create a temp table inside the stored procedure and insert the values split on the commas or any delimiter then do this

    SELECT * FROM Studio WHERE Id IN (select id from temptable)
    

    Then delete the table.

提交回复
热议问题