Wednesday, December 12, 2012

SQL Group By And Group_Concat Exapmle

SELECT       
SUBSTRING((SELECT ', ' + CAST([קוד זיהוי] AS VARCHAR(20))  FROM [dbo].[All] AllSub
     WHERE AllSub.משפחה = AllMain.משפחה
     For XML Path('')), 2, 8000) AS [קוד זיהוי]
    
FROM [dbo].[All] AllMain
GROUP BY משפחה, [שם] ,[רחוב] ,[מספר בית], [עיר];

point is that whatever field that is not in the GROUP BY the SQL Server wants you to group it somehow, and you need to to this XML trick for each one.
 

No comments:

Post a Comment