MY Table喜欢这样:
id Tag platform
1 #class1,#class2 CS
2 #class1 PS
3 #class2 CS
如果我将“'#class1'”作为参数传递给SP,只获得一条记录,即第二条记录。但需要第1条和第2条记录,因为#class1包含1,2行。请告诉我如何写这个我现在正在使用IN语句。通过使用获取记录。
MY SP:
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;
SELECT @TagList = '%' + RTRIM(LTRIM(@TagList)) + '%';
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 LIKE(select tag from #t)
END
如何修改请告诉我......
提前致谢..
答案 0 :(得分:1)
一种解决方案是在存储过程中使用LIKE运算符:
CREATE PROCEDURE FindTag @TagName char(50)
AS
SELECT @TagName = '%' + TRIM(@TagName) + '%';
SELECT Tag
FROM MyTable
WHERE Tag LIKE @TagName;
GO