I have a table with Contract\_Id, Site\_Name, and Hours columns… and now my requirement is to generate the comma seperated values by performing **Group By** on Contract\_Id column.

```
Contract_Id Site_Name   Hours
1           X           20
1           Y           20
2           X           20

```

Required Output in the Below Format

```
Contract_Id Site_Name   Hours
1           X,Y         40
2           X           20

```

I have tried with the below XML Path by doing group by... but it didn't work!!...

```
SELECT STUFF((SELECT ',' + Name,Contract_Id
            FROM #Tbl_Practice
            GROUP BY Name,Contract_Id
            FOR XML PATH('')) ,1,1,'') AS Txt

```

Can anyone provide me the SQL solution to handle this in a dynamic way….