本文介紹了SQL 根據(jù)兄弟節(jié)點(diǎn)屬性值選擇 XML 節(jié)點(diǎn)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
<Findings>
<Finding EcinRecordID="1042893">
<Name>Goal Length of Stay for the ORG</Name>
<Selected Value="0" DisplayValue="No"/>
</Finding>
<Finding EcinRecordID="1042894">
<Name>Goal Length of Stay for the GRG</Name>
<Selected Value="1" DisplayValue="Yes"/>
<NoteText>3 days</NoteText>
</Finding>
</Findings>
2 個挑戰(zhàn):
- 選擇Findings/Finding/Name 的節(jié)點(diǎn)值,其中Findings/Finding/Selected Value = "1"
- 選擇Findings/Finding/NoteText 的節(jié)點(diǎn)值,其中Findings/Finding/Selected Value = "1"
將其放入存儲過程.我已經(jīng)嘗試了至少 3 打使用查詢、存在和值的版本.可以得到Selected Value = '1',但是好像不能在Select語句中賦值對應(yīng)的Name值.
Putting this into a stored procedure. I've tried at least 3 dozen versions using query, exists and value. I can get the whether the Selected Value = '1', but can't seem to assign the corresponding Name value in the Select statement.
SELECT
p.value('(Payments[1]/Payment[1]/PreAuthCertNumber)[1]', 'varchar(20)') AS PriorAuthNumber
,qa.value('(Name[1])','varchar(255)') AS Question
,qa.value('(Findings/Finding/Name)[1]','varchar(255)') AS Answer
FROM #ValueExample
CROSS APPLY XMLDocument.nodes('/OutboundDataFeed/Patient/PatientAdmission') as t(p)
CROSS APPLY XMLDocument.nodes('/OutboundDataFeed/Patient/PatientAdmission/CMAssessments/CMAssessment/Sections/Section/Questions/Question') as u(qa)
謝謝!
推薦答案
declare @XML xml
set @XML = '
<Findings>
<Finding EcinRecordID="1042893">
<Name>Goal Length of Stay for the ORG</Name>
<Selected Value="0" DisplayValue="No"/>
</Finding>
<Finding EcinRecordID="1042894">
<Name>Goal Length of Stay for the GRG</Name>
<Selected Value="1" DisplayValue="Yes"/>
<NoteText>3 days</NoteText>
</Finding>
</Findings>'
select @XML.value('(/Findings/Finding[Selected/@Value = "1"]/Name/text())[1]', 'varchar(255)') as Name,
@XML.value('(/Findings/Finding[Selected/@Value = "1"]/NoteText/text())[1]', 'varchar(255)') as NoteText
結(jié)果:
Name NoteText
---------------------------------------- -------------------------
Goal Length of Stay for the GRG 3 days
這篇關(guān)于SQL 根據(jù)兄弟節(jié)點(diǎn)屬性值選擇 XML 節(jié)點(diǎn)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!