我的项目我有一个会话变量,该变量包含最近访问过的值的列表。借助这些值我需要从数据库中获取数据。为此,我编写了一个带有单个参数的存储过程(@myparam),但它仅给出从表中一行。 如何使用storedprocedure的会话列表从表中获取行列表?
答案 0 :(得分:0)
如果我理解你的话,试试这个
CREATE function [dbo].[csv2tbl](@list nvarchar(max), @delimiter nvarchar(10))
returns @res table ([index] int PRIMARY KEY, col nvarchar(max))
AS BEGIN
with tbl_for_csv as
(
select 0 as [index] ,left(@list + @delimiter+@delimiter,charindex(@delimiter,@list + @delimiter+@delimiter) -1)as col,
right(@list + @delimiter+@delimiter,len(@list + @delimiter+@delimiter) - charindex(@delimiter,@list + @delimiter+@delimiter)) as Str
union all
select [index]+1, left(Str,charindex(@delimiter,Str) - 1)as Col,
right(Str,len(Str) - charindex(@delimiter,Str)) from tbl_for_csv
where len(right(Str,len(Str) - charindex(@delimiter,Str))) > 0
)
INSERT @res
select [index], col from tbl_for_csv option (MAXRECURSION 0);
return;
END
GO
SELECT *
from YourTable
JOIN [dbo].[csv2tbl](@recentAssetList, ',') x ON x.col = yourtable.Id