简体   繁体   中英

Formatting multi-value SSRS Parameter

I am trying to pass in multiple values to a query via SSRS. They are IDs without leading zeros. I want to add the leading zeros so that the total digits in the ID is 7. (87886,88352) becomes (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. 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.

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.

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.

Second, notice that, eg

select RIGHT('0000000' + 14,7)

returns 14 not 0000014.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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