How to pass multiple values to a stored procedure in SQL Server 2008?
My table looks like this:
id Tag platform
1 #class1,#class2 CS
2 #class1 PS
3 #class2 CS
Stored procedure:
ALTER PROCEDURE [dbo].[usp_Get]-- 1,"'#class1,#class2'"
@Appid INT,
@TagList NVARCHAR (MAX)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @tags varchar(MAX)
set @tags = @TagList
create table #t (tag varchar(MAX))
set @tags = 'insert #t select ' + replace(@tags, ',', ' union select ')
exec(@tags)
Select
id FROM dbo.List WHERE ((appid=@Appid)) AND ((Tags IN(select tag from #t)
END
If I query
[dbo].[usp_Get] 1,"'#class1'"
I'm getting only the second row. But first row also has #class1
...
Please tell me ........