3 つのテーブルがあるという要件があります
連絡先情報
idContactinfo FirstName Lastname idCOmpanyid
---------------------------------------------------
1 Blah1 Blah1 1
2 Blah2 Blah2 1
3 Blah3 Blah3 1
4 Blah4 Blah4 1
連絡先ロール
idcontactrole IdContactRoleName idContactInfo
------------------------------------------------------
1 1 1
2 1 2
3 1 3
4 2 4
IdContactRoleLookup
idcontactRole RoleName
----------------------------------
1 Admin
2 Secretary
このような結果が得られるクエリが必要です
idcontactrolename Contacts
--------------------------------------------------------
Admin Blah1,Blah1;Blah2,Blah2,Blah3,Blah3
Secretary Blah4,Blah4
これは私が今まで持っているものです!!
SELECT l.sValue
, SUBSTRING((
SELECT C.sLast + ',' + C.sFirst + ';'
FROM contactinfo c
inner join contactrole crole
ON crole.idcontactinfo = c.idcontactinfo
WHERE crole.idcompany = '<<blah>>'
and c.idcompany = '<<blah>>'
FOR XML PATH('')
), 1, 1000000)
FROM CONTACTROLE CR
inner join contactinfo c on
cr.idcontactinfo = c.idcontactinfo
inner join lookupdata l on cr.idlookuprole = l.idlookupdata
where c.idcompany = '<<blah>>'