T-SQL stored procedure that accepts multiple Id values

后端 未结 6 958
既然无缘
既然无缘 2020-11-22 03:06

Is there a graceful way to handle passing a list of ids as a parameter to a stored procedure?

For instance, I want departments 1, 2, 5, 7, 20 returned by my stored

6条回答
  •  不思量自难忘°
    2020-11-22 03:48

    Try This One:

    @list_of_params varchar(20) -- value 1, 2, 5, 7, 20 
    
    SELECT d.[Name]
    FROM Department d
    where @list_of_params like ('%'+ CONVERT(VARCHAR(10),d.Id)  +'%')
    

    very simple.

提交回复
热议问题