Skip to content

Instantly share code, notes, and snippets.

@brandedoutcast
Last active December 28, 2015 02:49
Show Gist options
  • Save brandedoutcast/7430403 to your computer and use it in GitHub Desktop.
Save brandedoutcast/7430403 to your computer and use it in GitHub Desktop.
Get Multiple Phones For Single Customer without using mutiple inner joins.
SELECT DISTINCT
STUFF((SELECT DISTINCT ',' + CP.Phone_Nbr
FROM Customer_Phone CP
WHERE CM.Cust_Nbr = CP.Cust_Nbr
FOR XML PATH(''), TYPE)
.value('.', 'NVARCHAR(MAX)'), 1, 2, '') Phones
FROM Customer_Phone CM where CM.Cust_Nbr = 321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment