Good job of posting sample data + results. Thanks.
SELECT 'Summary' as Summary,
STUFF((SELECT ',' + CustomerName AS "text()"
FROM @CustomerOffices
WHERE OfficeId BETWEEN @FromOfficeId and @ToOfficeId
GROUP BY CustomerName
ORDER BY CustomerName
FOR XML PATH(''),TYPE).value('.','VARCHAR(MAX)'),1,1,'') AS CustomerNumbers,
STUFF((SELECT ',' + PostalCode AS "text()"
FROM @CustomerOffices
WHERE OfficeId BETWEEN @FromOfficeId and @ToOfficeId
GROUP BY PostalCode
ORDER BY PostalCode
FOR XML PATH(''),TYPE).value('.','VARCHAR(MAX)'),1,1,'') AS PostalCodes;
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537