I have a stored procedure GetReportItems:
GetReportItems
@ItemId varchar(max)
SELECT rt.ReportName, rt.ReportId, rg.OriginatedFrom
FROM Reports rt
JOIN ReportOrigin rg on rg.ReportId = rt.ReportId
WHERE rt.ColA = SUBSTRING(@ItemId, 1, 3)
AND rt.ColB = SUBSTRING(@ItemId, 4, Len(@ItemId) - 3)
@ItemId I can pass it to be as: ABC123Z OR DEF3456Y OR GHI7890X and it all works fine.
But I need to update this stored procedure to allow:
- pass in
ABC123Z~DEF3456Y~GHI7890Xas the@ItemId, the parameter to the stored procedure. - the stored procedure to split
@ItemIdstring on~and callSELECTon each of those string.
How could I do 1 and 2 above?
Even if I pass in multiple parameters to the stored proc, how can I aggregate SELECT on all these parameters?