Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- With distinctsection As
- (
- SELECT DISTINCT section
- FROM dbo.TableA
- )
- SELECT section, names= STUFF((
- SELECT ', ' + b.Name
- FROM dbo.TableB as b
- JOIN dbo.TableA as a
- ON a.AccountId = b.AccountId
- WHERE a.section = ds.section
- FOR XML PATH, TYPE).value(N'.[1]', N'nvarchar(max)'), 1, 1, '')
- FROM distinctsection ds
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement