sql server - SQL Combining 2 rows into one -
this question has answer here:
i have following query:
select qn.id, qn.title, qt.description, l.displayname language, count(q.id) questioncount dbo.questionnaires qn join dbo.questionnairetext qt on qn.id = qt.questionnaireid join dbo.questions q on q.questionnaireid = qn.id join dbo.languages l on l.id = qt.languageid (qn.questionnairetypeid = (select id questionnairetypes value = 'quiz')) group qn.id, qn.title, l.displayname, qt.description
which outputs following table:
36132a45-f09c-4eb5-9bd2-34a227ec03b9 test null english 1 36132a45-f09c-4eb5-9bd2-34a227ec03b9 test null spanish 1 24395bc7-a890-4514-ab35-7614e226b2a5 quiz null english 1 24395bc7-a890-4514-ab35-7614e226b2a5 quiz null spanish 1 03b13e61-6d7f-4597-8bb6-83889c7bfe29 g quiz null english 6 03b13e61-6d7f-4597-8bb6-83889c7bfe29 g quiz null spanish 6
what need query out put following:
36132a45-f09c-4eb5-9bd2-34a227ec03b9 test null english, spanish 1 24395bc7-a890-4514-ab35-7614e226b2a5 quiz null english, spanish 1 03b13e61-6d7f-4597-8bb6-83889c7bfe29 g quiz null english, spanish 6
i @ loss @ point. suggestions?
this how you'd for xml
:
select qn.id, qn.title, qt.description, stuff( isnull((select ', ' + l.displayname dbo.languages l l.id = qt.languageid group l.displayname xml path (''), type).value('.','varchar(max)'), ''), 1, 2, '') languages, count(q.id) questioncount dbo.questionnaires qn join dbo.questionnairetext qt on qn.id = qt.questionnaireid join dbo.questions q on q.questionnaireid = qn.id join dbo.questionnairetypes qtypes on qtypes.id = qn.questionnairetypeid qtypes.value = 'quiz' group qn.id, qn.title, l.displayname, qt.description
please note, i've moved where
criteria join
.
Comments
Post a Comment