Вот простой пример использования входного параметра CSV для сохраненного процесса.
create proc dbo.ListCustomers
(
@CustomerIDs varchar(MAX)
)
as
begin
-- convert paramter to xml
declare @XmlStr varchar(MAX)
set @XmlStr = '<R><I ID="' + replace(@CustomerIDs, ',', '"></I><I ID="') + '"></I></R>'
-- table variable that holds the ID's
declare @IdTable table (ID int)
-- load the XML document and insert id's to @IdTable
declare @XmlDoc int
exec sp_xml_preparedocument @XmlDoc out, @XmlStr
insert into @IdTable select ID from openxml(@XmlDoc, '/R/I',1) with (ID int)
exec sp_xml_removedocument @XmlDoc
-- use @IdTable in your query
select c.*
from tblCustomer c
join @IdTable as I on c.CustomerID = I.ID
end
go
-- usage:
-- exec ListCustomers '3823,3838,3845,3925,4051'