简体   繁体   English

格式化多值SSRS参数

[英]Formatting multi-value SSRS Parameter

I am trying to pass in multiple values to a query via SSRS. 我试图通过SSRS将多个值传递给查询。 They are IDs without leading zeros. 它们是没有前导零的ID。 I want to add the leading zeros so that the total digits in the ID is 7. (87886,88352) becomes (0087886,0088352). 我想添加前导零,以便ID中的总位数为7。(87886,88352)变为(0087886,0088352)。 I had the idea to use a cursor or put it into a temp table, but no matter what I think to do, I run into the same issue where there's just not much I can do with a list of IDs. 我有使用游标或将其放入临时表的想法,但是无论我想做什么,我都会遇到同一问题,即我对ID列表的处理不多。 No matter what I try, at some point I'm going to need to deal with the list dynamically. 无论我尝试什么,在某个时候我都需要动态处理列表。 Either dynamically appending the zeros, counting the values, or adding them as rows to a table. 动态地添加零,计数值或将它们作为行添加到表中。 In any case, I'm just not sure how to deal with a list from SSRS in this fashion. 无论如何,我只是不确定如何以这种方式处理来自SSRS的列表。

SELECT * FROM PERSON WHERE ID IN (RIGHT('0000000' + @pIDs,7))

That's the idea I'm going for, where @pIDs is a list from SSRS. 这就是我要的想法,其中@pIDs是SSRS的列表。

Try removing the leading zeros from the data instead: 尝试从数据中删除前导零:

SELECT * 
FROM PERSON 
WHERE -1 < CHARINDEX(',' + CAST(CAST(ID AS INT) AS VARCHAR(7)) + ',', ','+@pIds+',')

First, notice that the data type of: 首先,请注意以下数据类型:

RIGHT('0000000' + @pIDs,7)

is integer. 是整数。 Your ID column may not be of int type, because you see them in the '0087886' format. 您的ID列可能不是int类型,因为您看到的是'0087886'格式。

Second, notice that, eg 其次,请注意,例如

select RIGHT('0000000' + 14,7)

returns 14 not 0000014. 返回14而不是0000014。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM