0

我有一个带有多个值参数的 SSRS 报告,当我尝试使用多个值生成 sp 时,当我在 SSRS 环境(测试)上时,我得到了相反的结果,即使我选择了多个值,结果我只得到了第一行,下面是我的来源;

sp 生成多行

SELECT RIGHT('0'+StoreCode,4) + ' - ' + LTRIM(RTRIM(StoreName)) AS Result
FROM tblInterface_Branch
WHERE StoreCode IN (SELECT * FROM list_to_tbl(@var))

函数,我从教程中复制的

-- from http://www.sommarskog.se/arrays-in-sql-2005.html
-- original name: iter$simple_intlist_to_tbl
ALTER FUNCTION list_to_tbl (@list nvarchar(MAX))
RETURNS @tbl TABLE (number int NOT NULL) AS
BEGIN
DECLARE @pos        int,
       @nextpos    int,
       @valuelen   int 

SELECT @pos = 0, @nextpos = 1 

WHILE @nextpos > 0
BEGIN
  SELECT @nextpos = charindex(',', @list, @pos + 1)
  SELECT @valuelen = CASE WHEN @nextpos > 0
                          THEN @nextpos
                          ELSE len(@list) + 1
                     END - @pos - 1
  INSERT @tbl (number)
     VALUES (convert(int, substring(@list, @pos + 1, @valuelen)))
  SELECT @pos = @nextpos
END
RETURN
END

有什么我想念的吗?

4

0 回答 0