views:

743

answers:

2

In my SQL database, I have a one-to-many relationship, something like this:

Teacher  Student
John     Alex
John     Mike
John     Sean
Bob      Jack
Gary     George
Gary     Paul

I'd like to display a table listing each teacher, with their students as a comma-delimited list, like this:

Teacher  Students
John     Alex, Mike, Sean
Bob      Jack
Gary     George, Paul

This question describes how to do this on the SQL Server end, but is there a way to do this on the SSRS side of things?

+1  A: 

Add a grouping on teacher, and use the .net Join to append the detail rows

Join is demonstrated for multi-value parameters in BOL... so in theory it can be used for the result dataset

Join

Join and multi-value parameters

gbn
This looks promising, gbn. But I'm having trouble figuring out how to get the field values for a specific group as an array. Any ideas?
AaronSieb
As a concrete example I've tried putting this expression in the group footer: =Join(Fields!Student, ", ") . This compiled, but resulted in a #Error.
AaronSieb
Sorry: looks like I'm wrong. Just when you think you know RS.Ideas: 1. use a matrix to turn rows into columns but you lose the nice CSV format2. Subreport where you load the subset as a parameter and use JOIN on that
gbn
The Subreport is promising, but passing the field values into a multi-value parameter doesn't seem to be possible. The matrix is close, but lacks some of the features of a comma separated list (such as word wrap).
AaronSieb
A: 

I've been researching this a bit, and have come across another work-around.

Create a custom function, such as GetStudentList(TeacherId As Integer, ConnectionString As String), which is intended to return the list of students based on the specified teacher.

This function can then be written to open a connection to the database, run a query, process the results, and then return them. But that means opening the connection and running the query for every row, which seems like a lot of overhead for this type of formatting (not to mention the need to pass in a Connection String).

This is based largely on an Experts' Exchange article.

AaronSieb