T-SQL stored procedure that accepts multiple Id values

后端 未结 6 957
既然无缘
既然无缘 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:45

    A superfast XML Method, if you want to use a stored procedure and pass the comma separated list of Department IDs :

    Declare @XMLList xml
    SET @XMLList=cast(''+replace(@DepartmentIDs,',','')+'' as xml)
    SELECT x.i.value('.','varchar(5)') from @XMLList.nodes('i') x(i))
    

    All credit goes to Guru Brad Schulz's Blog

提交回复
热议问题