Guest User

Untitled

a guest
Apr 30th, 2016
914
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. With distinctsection As
  2. (
  3. SELECT DISTINCT section
  4. FROM dbo.TableA
  5. )
  6. SELECT section, names= STUFF((
  7. SELECT ', ' + b.Name
  8. FROM dbo.TableB as b
  9. JOIN dbo.TableA as a
  10. ON a.AccountId = b.AccountId
  11. WHERE a.section = ds.section
  12. FOR XML PATH, TYPE).value(N'.[1]', N'nvarchar(max)'), 1, 1, '')
  13. FROM distinctsection ds
RAW Paste Data