declare @NominationAwardFocus table ( AwardFocusID int, ...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Anime and Manga

Q&A for anime and manga fans

-- Enter Query Title
-- Enter Query Description

declare @NominationAwardFocus table
(
  AwardFocusID int,
  NominationID int
)

insert into @NominationAwardFocus values
(5, 19),
(7, 19),
(8, 19)

declare @AwardFocus table
(
  AwardFocusID int,
  AwardFocusName nvarchar(10)
)

insert into @AwardFocus values
(1, 'Name 1'),
(2, 'Name 2'),
(3, 'Name 3'),
(4, 'Name 4'),
(5, 'Name 5'),
(6, 'Name 6'),
(7, 'Name 7'),
(8, 'Name 8'),
(9, 'Name 9')

select stuff((select ', '+AF.AwardFocusName
              from @AwardFocus as AF
                inner join @NominationAwardFocus as NAF2
                  on AF.AwardFocusID = NAF2.AwardFocusID
              where NAF1.NominationID = NAF2.NominationID
              for xml path(''),  type).value('.', 'nvarchar(max)'), 1, 2, '') as AwardFocusNames
from @NominationAwardFocus as NAF1
group by NAF1.NominationID

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results