CREATE TABLE #temp( ID INT, name NVARCHAR(max), age int, address ) ) insert into #temp select ID, name = ( stuff( (select ',' + SN from #temp where ID = A.ID and age = A.age for xml path('')), , , '' ) ) , age, address from #temp as A group by A.age,…