本文介紹了SQL 根據兄弟節點屬性值選擇 XML 節點的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送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 個挑戰:
- 選擇Findings/Finding/Name 的節點值,其中Findings/Finding/Selected Value = "1"
- 選擇Findings/Finding/NoteText 的節點值,其中Findings/Finding/Selected Value = "1"
將其放入存儲過程.我已經嘗試了至少 3 打使用查詢、存在和值的版本.可以得到Selected Value = '1',但是好像不能在Select語句中賦值對應的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
結果:
Name NoteText
---------------------------------------- -------------------------
Goal Length of Stay for the GRG 3 days
這篇關于SQL 根據兄弟節點屬性值選擇 XML 節點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!