问题
I have a report in reporting services and I want to concatenate all the distinct values of a column separating by commas and place the value in a textbox. I know I could do it in the SQL using one of the answers here. But I'd rather not change the sql and just do it in the report if possible.
Example: I've got a dataset with several fields, one of which is category. Say the values are "Phone", "Service", "Phone", "Accessory", "Case", "Case". I want the textbox in my report to end up with the value "Accessory, Case, Phone".
In case it makes a difference, it is SSRS 2008 R2.
回答1:
I've figured out a way, although not the most elegant solution. I've added an internal parameter to get the list of all possible categories as well as an additional parameter to get rid of the duplicates. I've followed the steps here (starting at the part where they are adding dummy parameters) to do the above.
Essentially,
- Create a mulit-value parameter using the dataset and field I want for available/selected values. Be sure to mark as internal on the General tab.
- Add the RemoveDuplicates function shown in the link to the Code tab in Report Properties
- Create a second multi-value parameter that uses the RemoveDuplicates function. Similarly, be sure to mark as internal.
After that I used the Join function on the second parameter to create the comma delimited list.
来源:https://stackoverflow.com/questions/14046186/concatenate-distinct-row-values-for-field-in-reporting-services