SQL Server - help on a difficult query
Posted on 2011-03-14
This may be pretty strait forward, but I have no idea how to do it or even to google out to do it.
This query is coming from only one table called tbProjectMaterial. Inside this table I have relevant columns: ProjectID, CustomerPO, and LineNumber.
I need the query to return back data for a given ProjectID and where CustomerPO is not null.
More complex, I need to group by CustomerPO, show a count of the number of records making up the group, and most complex, I need to have a list in the third column of all the line numbers associated with the CustomerPO.
So the data returned might look something like this...
for ProjectID = 140
CustomerPO Count LineNumbers
745 3 294, 295, 296
748 2 297, 298
750 5 299, 300, 302, 304, 305
I can pretty much do everything except for the grouping of associated line numbers into one record in a comma delimited fashion as I'm showing above.
Thanks for any help on this.