Вы находитесь на странице: 1из 5

CREATE PROC sqlrewr.

pr_custom_pwc_conference_mtm_fetchdata_test
AS
BEGIN
DECLARE @co_line_of_service INT
SELECT @co_line_of_service=field_id from lo_custom_field where
tag='US_CO_LINE_OF_SERVICE'

SELECT
src as '@src',
[Date] as '@date',
(
SELECT
xid,
name,
internal
FROM [SQLREWR].__Integration_PWC_US__outbound_vendor as vendor
FOR XML AUTO, ROOT ('vendors'), TYPE
),
(
SELECT
email,
lname,
fname,
xid
FROM [SQLREWR].__Integration_PWC_US__outbound_instructor as instructor
FOR XML AUTO, ROOT ('instructors'), TYPE
),
(
SELECT
xid,
ol,
descr AS [desc],
name
FROM [SQLREWR].__Integration_PWC_US__outbound_course as course
FOR XML AUTO, ROOT ('courses'), TYPE
),
(
SELECT
xid,
name,
[to]
FROM [SQLREWR].__Integration_PWC_US__outbound_location as location
FOR XML AUTO, ROOT ('locations'), TYPE
),
(
SELECT
(
select conference.conf_id AS '@xid',
conference.descr AS '@desc',
conference.name AS '@name',
(
SELECT
conferenceanchora.xid AS '@xid',
conferenceanchora.xvendor AS '@xvendor',
--lp.provider_name AS '@xvendor',
conferenceanchora.classname AS '@classname',
conferenceanchora.xloc AS '@xloc',
CONVERT(VARCHAR(10),conferenceanchora.ed,101) AS '@ed',
CONVERT(VARCHAR(10),conferenceanchora.sd,101) AS '@sd',

(
SELECT
classInstructor.xid AS '@xid'
FROM [SQLREWR].__Integration_PWC_US_ValidSesn_Conference e
--on conf.conf_id=e.conf_id
inner join [SQLREWR].__Integration_PWC_US__outbound_class
conferenceanchor on e.session_id=conferenceanchor.classxid
inner join
[SQLREWR].__Integration_PWC_US__outbound_classInstructor classInstructor on
conferenceanchor.classxid=classInstructor.classxid
WHERE e.conf_id=conference.conf_id
FOR XML PATH ('classInstructor'), TYPE
),
(
SELECT
'true' as '@email',
LTRIM(RTRIM(title)) as '@sid'
FROM (
SELECT DISTINCT
title --as 'sid'
FROM
[SQLREWR].__Integration_PWC_US__outbound_survey survey
INNER JOIN
[SQLREWR].__Integration_PWC_US_ValidSesn_Conference e on
survey.object_id=e.session_id
WHERE ISNULL(title,'')<>'' and
e.conf_id=conference.conf_id and survey.flag=1
UNION ALL
SELECT DISTINCT
title1-- as 'sid'
FROM
[SQLREWR].__Integration_PWC_US__outbound_survey survey
INNER JOIN
[SQLREWR].__Integration_PWC_US_ValidSesn_Conference e on
survey.object_id=e.session_id
WHERE ISNULL(title1,'')<>'' and
e.conf_id=conference.conf_id and survey.flag=1
UNION ALL
SELECT DISTINCT
title2 --as 'sid'
FROM
[SQLREWR].__Integration_PWC_US__outbound_survey survey
INNER JOIN
[SQLREWR].__Integration_PWC_US_ValidSesn_Conference e on
survey.object_id=e.session_id
WHERE ISNULL(title2,'')<>'' and
e.conf_id=conference.conf_id and survey.flag=1
UNION ALL
SELECT DISTINCT
title3 --as 'sid'
FROM
[SQLREWR].__Integration_PWC_US__outbound_survey survey
INNER JOIN
[SQLREWR].__Integration_PWC_US_ValidSesn_Conference e on
survey.object_id=e.session_id
WHERE ISNULL(title3,'')<>'' and
e.conf_id=conference.conf_id and survey.flag=1
) survey
FOR XML PATH ('survey'), TYPE
),

(
SELECT
student.email AS '@email',
student.xid AS '@xid',
student.cancel AS '@cancel',
student.jt AS '@jt',
student.lastname AS '@lastname',
student.firstname AS '@firstname',
(
SELECT
xid as '@xid',
value as '@value',
qid as '@qid'
FROM
[SQLREWR].__Integration_PWC_US__outbound_sdata sdata
where sdata.user_id=student.user_id and
ISNULL(xid,'')<>''
FOR XML PATH ('sdata'), TYPE
)
FROM
[SQLREWR].__Integration_PWC_US__outbound_studenthelper student
WHERE student.conf_id=conference.conf_id
FOR XML PATH ('student'), TYPE
)

from [SQLREWR].__Integration_PWC_US__outbound_course conferencea


inner join lo on conferencea.xid=lo.root_object_id
inner join [SQLREWR].__Integration_PWC_US_ValidSesn_Conference
conf on conf.session_id=lo.object_id
inner join [SQLREWR].__Integration_PWC_US__outbound_class
conferenceanchora on conf.session_id=conferenceanchora.classxid

where conferencea.xid=conference.xid AND


conferenceanchora.xid='09DCA195-CC43-4147-B18A-CCCC2470697D'
FOR XML PATH ('conferenceanchor'), TYPE
),
(
--Conference Group
SELECT
--gh.conf_id+CAST(CONVERT(VARCHAR(10),gh.sd,112) as varchar)
+REPLACE(SUBSTRING(CAST(CONVERT(VARCHAR(10),gh.sd,114) as varchar),1,5),':','')
+gh.code as '@xid',--commented by mbisht--211264435
LEFT(gh.conf_id+CAST(CONVERT(VARCHAR(10),gh.sd,112) as varchar)
+REPLACE(SUBSTRING(CAST(CONVERT(VARCHAR(10),gh.sd,114) as varchar),1,5),':','')
+gh.code,5) + RIGHT(gh.conf_id+CAST(CONVERT(VARCHAR(10),gh.sd,112) as varchar)
+REPLACE(SUBSTRING(CAST(CONVERT(VARCHAR(10),gh.sd,114) as varchar),1,5),':','')
+gh.code,15) as '@xid',
REPLACE(CAST(CONVERT(VARCHAR(10),gh.sd,102) as varchar),'.',' ')+ ' '
+DATENAME(dw,gh.sd)+' '+SUBSTRING(CAST(CONVERT(VARCHAR(10),gh.sd,114) as
varchar),1,5)+' '++gh.code as '@name',
gh.order_no as '@order',
(
SELECT c.xid AS '@xid',
c.xvendor as '@xvendor',
c.classname AS '@classname',
c.xloc AS '@xloc',
CONVERT(VARCHAR(10),c.ed,101) AS '@ed',
CONVERT(VARCHAR(10),c.sd,101) AS '@sd',
A.order_no as '@order',
'false' as '@mandatory',
c.xcourse as '@xcourse',
(
SELECT
classInstructor.xid AS '@xid'
FROM [SQLREWR].__Integration_PWC_US_ValidSesn_Elective e
--on conf.conf_id=e.conf_id
inner join [SQLREWR].__Integration_PWC_US__outbound_class
conferenceanchor on e.session_id=conferenceanchor.classxid
inner join
[SQLREWR].__Integration_PWC_US__outbound_classInstructor classInstructor on
conferenceanchor.classxid =classInstructor.classxid
WHERE classInstructor.classxid=c.classxid
FOR XML PATH ('classInstructor'), TYPE
),
(
SELECT
'true' as '@email',
LTRIM(RTRIM(title)) as '@sid'
FROM (
SELECT DISTINCT
title --as 'sid'
FROM
[SQLREWR].__Integration_PWC_US__outbound_survey survey
INNER JOIN
[SQLREWR].__Integration_PWC_US_ValidSesn_Elective el on
survey.object_id=el.session_id
WHERE ISNULL(title,'')<>'' and
el.session_id=c.classxid and el.conf_id=e.conf_id
UNION ALL
SELECT DISTINCT
title1-- as 'sid'
FROM
[SQLREWR].__Integration_PWC_US__outbound_survey survey
INNER JOIN
[SQLREWR].__Integration_PWC_US_ValidSesn_Elective el on
survey.object_id=el.session_id
WHERE ISNULL(title1,'')<>'' and
el.session_id=e.session_id and el.conf_id=e.conf_id
UNION ALL
SELECT DISTINCT
title2 --as 'sid'
FROM
[SQLREWR].__Integration_PWC_US__outbound_survey survey
INNER JOIN
[SQLREWR].__Integration_PWC_US_ValidSesn_Elective el on
survey.object_id=el.session_id
WHERE ISNULL(title2,'')<>'' and
el.session_id=e.session_id and el.conf_id=e.conf_id
UNION ALL
SELECT DISTINCT
title3 --as 'sid'
FROM
[SQLREWR].__Integration_PWC_US__outbound_survey survey
INNER JOIN
[SQLREWR].__Integration_PWC_US_ValidSesn_Elective el on
survey.object_id=el.session_id
WHERE ISNULL(title3,'')<>'' and
el.session_id=e.session_id and el.conf_id=e.conf_id
) survey
FOR XML PATH ('survey'), TYPE
)
FROM [SQLREWR].__Integration_PWC_US__outbound_class c
INNER JOIN
(
select sd,conf_id,--rec_count,
order_no,code
from [SQLREWR].__Integration_PWC_US__outbound_grouphelper g

)A on A.sd=c.sd and A.conf_id=gh.conf_id and A.code=gh.code


inner join [SQLREWR].__Integration_PWC_US_ValidSesn_Elective e on
c.xid=e.session_id
WHERE e.conf_id=gh.conf_id and c.sd=gh.sd
FOR XML PATH ('conferencesession'), TYPE
)
from [SQLREWR].__Integration_PWC_US__outbound_grouphelper gh
where conference.conf_id=gh.conf_id
FOR XML PATH ('conferencegroup'), TYPE

from [SQLREWR].__Integration_PWC_US__outbound_coursehelper conference

FOR XML PATH('conference'), TYPE


)
FOR XML PATH('conferences'), TYPE

)
FROM [SQLREWR].__Integration_PWC_US__outbound_import o
FOR XML PATH('import'), TYPE

END

Вам также может понравиться