I referenced This and others stacks
This is what I have done:
SELECT
ReportDate,
ReportID = STUFF((SELECT ',' + CAST(t1.ReportID AS varchar(50))
FROM BackEndEfficiency t1
WHERE t1.ReportID = t2.ReportID
FOR XML PATH ('')), 1, 1, '')
FROM
BackEndEfficiency t2
GROUP BY
ReportDate
Error:
Column 'BackEndEfficiency.ReportID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Why am I getting this error as I want the ReportDate
to be grouped by?
Example of data structure
ReportDate ReportID
--------------------
2020-03-11 30
2020-03-11 31
2020-03-16 32
2020-03-16 33
I would like to get this output:
ReportDate ReportID
--------------------
2020-03-11 30,31
2020-03-16 32,33