У меня есть несколько запросов для заполнения определенного столбца.
Запрос 1:
with cte as
(
select distinct
w.Work_WorkID, k.Name as "Secretariat_Attendees"
from
d, m, s, w, a, k
where
d.DataID = m.Map_MapObjID
and m.Map_MapID = s.SubWork_MapID
and s.SubWork_WorkID = w.Work_WorkID
and w.Work_WorkID = a.WF_ID
and d.DataID = 35269818
and a.WF_AttrID = 17
and k.ID = a.WF_ValInt
)
select distinct
t2.Work_WorkID,
stuff((select N' ; ' + Secretariat_Attendees
from (select Work_WorkID, Secretariat_Attendees
from cte t1
where t1.Work_WorkID = t2.Work_WorkID) AS t
for xml path('')), 1, 2, '') + N'' Secretariat_Attendees
from cte t2;
Выход запроса 1:
Work_WorkID Secretariat_Attendees
----------------------------------------------------
35273587 Admin CEO Office ; BD_TestUser ; Diana
35277687 10023165 ; 10036755 ; 10075193
Запрос 2:
with cte as (
select Distinct w.Work_WorkID,k.Name as "Committee_Attendees" from d, m, s, w, a, k
where d.DataID=m.Map_MapObjID and m.Map_MapID=s.SubWork_MapID and s.SubWork_WorkID=w.Work_WorkID
and w.Work_WorkID=a.WF_ID and d.DataID=35269818 and a.WF_AttrID=5 and k.ID=a.WF_ValInt
)
select distinct t2.Work_WorkID,
stuff((select N' ; ' + Committee_Attendees
from (select Work_WorkID, Committee_Attendees
from cte t1 where t1.Work_WorkID = t2.Work_WorkID) AS t
for xml path('')
), 1, 2, '') + N'' Committee_Attendees from cte t2;
Вывод запроса 2:
Work_WorkID Committee_Attendees
35273587 Deva ; User 1
35277687 User3 ; User 4
Как объединить оба этих запроса в один, чтобы получить желаемый вывод ниже на основе Work_WorkID?
Work_WorkID Secretariat_Attendees Committee_Attendees
35273587 Admin CEO Office ; BD_TestUser ; Diana Deva ; User 1
35277687 10023165 ; 10036755 ; 10075193 User3 ; User 4