Sometimes, we need to aggregate strings in SSRS designer. In
situations, when we are using Report Model as data source this is very
much needed.
There are many Aggregation functions available in SSRS, but to implement string concatenation/aggregation, we can’t directly use any of the provided function directly. But, by using SSRS custom code and RunningValue aggregate function we can achieve this as shown below.
For reference the same report is attached herewith. You can find the report below.
Step-1 Create a dataset.
Note:- This example is just created to simulate the situation.
Step-2 Create a report with RowGrouping on ID.
Step-3 Add custom code
Step-4 Add colum with following expression
Step-5 Run Report.
Here, we can see the concatenated rows as shown in below.

There are many Aggregation functions available in SSRS, but to implement string concatenation/aggregation, we can’t directly use any of the provided function directly. But, by using SSRS custom code and RunningValue aggregate function we can achieve this as shown below.
For reference the same report is attached herewith. You can find the report below.
Step-1 Create a dataset.
Note:- This example is just created to simulate the situation.
DECLARE @tab TABLE ( id INT, name NVARCHAR(100), phoneNumber NVARCHAR(100))INSERT INTO @tab (id,name,phonenumber)VALUES (1,'Sachin','9824512345'), (1,'Sachin','26612345' ), (2,'Rahul','99922299922'), (2,'Rahul','1234567890'), (2,'Rahul','234561234')
SELECT a.id ,a.name ,a.phoneNumber FROM @tab aStep-3 Add custom code
Dim Num As Integer = 0 Dim tempstr As String = ""Function AggregateString(ID as Integer, PhoneNumber as String)If ID = Num Thentempstr = tempstr + "," + PhoneNumberElseNum = IDtempstr = PhoneNumberEnd IfReturn tempStrEnd Function=RunningValue(Code.AggregateString(Fields!id.Value,Fields!phonenumber.Value),Max,"id")Here, we can see the concatenated rows as shown in below.
No comments:
Post a Comment