Search This Blog

Display comma Separated Values in SSRS Report

Display comma Separated Values in SSRS Report

Issue-How to Display comma Separated Values in SSRS Report.
Being a SQL and BI Developer I am quite active in various SQL and BI related groups including my own SQL and BI group.So there one of the member of the group asked be the below Question.

IN SSRS I have a table like this 

Id cellNo 
1 9xxx
1 8xxx
1 7xxx
2 9xxx
2 8xxx
3 7xx
4 9xxx

 output Required.

Id cellNo
1 9xxx,8xxx,7xxx
2 9xxx,8xxx
3 7xxx
4 9xxx

Ast it’s a common Requirement with lots of Geeks who are working with SSRS so I thought of writing a post on this  in my Site.

Solutions-In order to get the values as comma separated first we will create a test table with above records.
CREATE TABLE Number(Id int, CellNo varchar(100))
 INSERT INTO Number VALUES
( 1, '9xxx'),
(1, '8xxx'),
(1, '7xxx'),
(2, '9xxx'),
(2,' 8xxx'),
(3, '7xxx'),
(4,'9xxx')
           
 SELECT   * FROM  Number 

So once we have created a table we will create a Datasource and dataset in the SSRS Report and will show the same table in SSRS Report
.
Now in order to get the same format as required go to design view of Report.

Write the below Expression in the cell highlighted in Yellow.


=Join (LookUpSet (Fields!Id.Value, Fields!Id.Value, Fields!CellNo.Value, "DataSet1"), ",")

Preview the Report

Now you are able to see the desired Result with comma separated values Group on Id.But you will notice that there are duplicates rows coming .

So, In order to Remove duplicates Records in SSRS .

Go to design view of Report

Select the second Row

Click on Row Visibility

Select show and hide based on Expression as in Screenshot.

Write the below Expression


=iif(Fields!Id.Value = Previous(Fields!Id.Value), True, False)

Click ok

Preview the Report.

We will get the exact desired format without any duplicate Records.


Note:If you want to Get the same format in SQL check my older post on same.
http://www.sqlandssrssolutions.com/search?q=comma+separated 





7 comments:

  1. Excellent post and it helped me a lot. Thanks for this post.

    ReplyDelete
  2. how to do it in reverse manner dynamically....?
    Let say i have comma separated values in every row and i want to split it into individual rows in SSRS 2012.
    Existed:
    S.no,Description
    1,a,b,c
    2,x,y,z
    3,p,q,r

    Required output:
    S.no,Description
    1,a
    1,b
    1,c
    2,x
    2,y
    2,z
    3,p
    3,q
    3,r

    ReplyDelete
  3. Great work and it save my time a lot. Thanks for this post. :)

    ReplyDelete
  4. Did anyone notice the comma that comes before the values, any solution to elimate thevfirst comma?

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Even I'm also facing the same issue.
      Also I want the values to be sorted.

      Any help ?

      Delete
  5. The Orphans -A wager on any of the numbers which aren't covered by the other referred to as bets. The odds 카지노 사이트 in European roulette are barely higher since there isn't a|there isn't any} 00 on the board. Play European roulette as it has larger winning chances compared to with} American roulette.

    ReplyDelete