I have a report, which is developed in SSRS 2005 and i am using a stored procedure to fetch the results from the database. The result on the report output is very simple as shown below in the figure.
If suppose I am looking for different Members
eg:-
MemberID
c108
c109
c110
...
as shown in the figure below.
So for each member there are various USERS and for each user there will be various ROLES.

But I need all in one row as shown below.
MemberID UserID Roles
c108 22492 SystemOperator,ItemResearcher,Non-Decision Role,Security Administrator, Decisioning Administrator,Reporting,Corporate Administrator
c108 22469 SystemOperator,ItemResearcher,Non-Decision Role,Security Administrator,Decisioning Administrator
So that all roles for each user can be shown in one single row in SSRS (reporting) with ‘,’ seperated.
What is the easiest way to write a stored procedure to produce a result just like this.
Please Note:- There may be some change, if my boss wants me to get the userId also in just 1 row with ‘,’ seperated, then I must be able to modify the query easily. Please suggest me. Thank you so much for taking time to read and understand my question.
If this were MySQL, you’d use the GROUP_CONCAT function to create that comma separated list:
However since this is MSSQL you’ll need to fake GROUP_CONCAT something like this