我有3個臨時表全部由3個獨立的查詢填充,並且以1對1關係相互關聯,這些表是DemographicRecord,GPRegistrationDetails,MaternityBookingDetails。所有3個列都不相同,但每個列都共享PatientID密鑰。我的問題是使用XML路徑,我如何根據下面的格式從3個相關的數據集中輸出XML。使用TSQL和XML路徑來生成XML輸出
<MAT001MothersDemographics>
<LocalPatientIdMother>BLANKED</LocalPatientIdMother>
<OrgCodeLocalPatientIdMother>BLANKED</OrgCodeLocalPatientIdMother>
<OrgCodeRes>BLANKED</OrgCodeRes>
<NHSNumberMother>BLANKED</NHSNumberMother>
<NHSNumberStatusMother>BLANKED</NHSNumberStatusMother>
<PersonBirthDateMother>BLANKED</PersonBirthDateMother>
<Postcode>BLANKED</Postcode>
<EthnicCategoryMother>BLANKED</EthnicCategoryMother>
<PersonDeathDateTimeMother>BLANKED</PersonDeathDateTimeMother>
<MAT003GPPracticeRegistration>
<LocalPatientIdMother>BLANKED</LocalPatientIdMother>
<OrgCodeGMPMother>BLANKED</OrgCodeGMPMother>
<StartDateGMPRegistration>BLANKED</StartDateGMPRegistration>
<EndDateGMPRegistration>BLANKED</EndDateGMPRegistration>
<OrgCodeCommissioner>BLANKED</OrgCodeCommissioner>
</MAT003GPPracticeRegistration>
<MAT101BookingAppointmentDetails>
<AntenatalAppDate>BLANKED</AntenatalAppDate>
<LocalPatientIdMother>BLANKED</LocalPatientIdMother>
<EDDAgreed>BLANKED</EDDAgreed>
<EDDMethodAgreed>BLANKED</EDDMethodAgreed>
<PregnancyFirstContactDate>BLANKED</PregnancyFirstContactDate>
<PregnancyFirstContactCareProfessionalType>BLANKED</PregnancyFirstContactCareProfessionalType>
<LastMenstrualPeriodDate>BLANKED</LastMenstrualPeriodDate>
<PhysicalDisabilityStatusIndMother>BLANKED</PhysicalDisabilityStatusIndMother>
<FirstLanguageEnglishIndMother>BLANKED</FirstLanguageEnglishIndMother>
<EmploymentStatusMother>BLANKED</EmploymentStatusMother>
<SupportStatusMother>BLANKED</SupportStatusMother>
<EmploymentStatusPartner>BLANKED</EmploymentStatusPartner>
<PreviousCaesareanSections>BLANKED</PreviousCaesareanSections>
<PreviousLiveBirths>BLANKED</PreviousLiveBirths>
<PreviousStillBirths>BLANKED</PreviousStillBirths>
<PreviousLossesLessThan24Weeks>BLANKED</PreviousLossesLessThan24Weeks>
<SubstanceUseStatus>BLANKED</SubstanceUseStatus>
<SmokingStatus>BLANKED</SmokingStatus>
<CigarettesPerDay>BLANKED</CigarettesPerDay>
<AlcoholUnitsPerWeek>BLANKED</AlcoholUnitsPerWeek>
<FolicAcidSupplement>BLANKED</FolicAcidSupplement>
<MHPredictionDetectionIndMother>BLANKED</MHPredictionDetectionIndMother>
<PersonWeight>BLANKED</PersonWeight>
<PersonHeight>BLANKED</PersonHeight>
<ComplexSocialFactorsInd>BLANKED</ComplexSocialFactorsInd>
</MAT101BookingAppointmentDetails>
</MAT001MothersDemographics>
到目前爲止,我曾嘗試:
SELECT
(SELECT * FROM #temp2
JOIN #temp ON #temp2.LocalPatientIdMother = #temp.LocalPatientIdMother
JOIN #temp3 ON #temp2.LocalPatientIdMother = #temp3.LocalPatientIdMother
FOR XML PATH('MAT001'), TYPE) AS 'MAT001MothersDemographics'
FOR XML PATH(''), ROOT('root')
但這不是正確的形狀,可有人提醒我如何使用TSQL和有效地XML PATH這樣我就可以產生上面的輸出?我目前正在獲取每個記錄在其他數據顯示之前重複的人口統計數據?
<MAT001MothersDemographics>
<MAT001>
<LocalPatientIdMother>BLANKED</LocalPatientIdMother>
<OrgCodeLocalPatientIdMother>BLANKED</OrgCodeLocalPatientIdMother>
<OrgCodeRes>BLANKED</OrgCodeRes>
<NHSNumberMother>BLANKED</NHSNumberMother>
<NHSNumberStatusMother>BLANKED</NHSNumberStatusMother>
<PersonBirthDateMother>BLANKED</PersonBirthDateMother>
<Postcode>BLANKED</Postcode>
<EthnicCategoryMother>BLANKED</EthnicCategoryMother>
<PersonDeathDateTimeMother>BLANKED</PersonDeathDateTimeMother>
</MAT001>
</MAT001MothersDemographics>
<MAT001MothersDemographics>
<MAT001>
<LocalPatientIdMother>BLANKED</LocalPatientIdMother>
<OrgCodeLocalPatientIdMother>BLANKED</OrgCodeLocalPatientIdMother>
<OrgCodeRes>BLANKED</OrgCodeRes>
<NHSNumberMother>BLANKED</NHSNumberMother>
<NHSNumberStatusMother>BLANKED</NHSNumberStatusMother>
<PersonBirthDateMother>BLANKED</PersonBirthDateMother>
<Postcode>BLANKED</Postcode>
<EthnicCategoryMother>BLANKED</EthnicCategoryMother>
<PersonDeathDateTimeMother>BLANKED</PersonDeathDateTimeMother>
</MAT001>
</MAT001MothersDemographics>
非常感謝
您是否可以爲臨時表提供一些示例(清理過的)數據? –
嗨丹謝謝,查詢是巨大的,所以我不會粘貼在這裏,但是,本質上他們填充3表 – jimmy8ball
如果它有幫助臨時是MAT003,temp2是MAT001和temp3是MAT101和表匹配架構在第一個XML塊 – jimmy8ball