SQL Select XML Node based on sibling node attribute value

AderyNiligere

New Member
\[code\]<Findings> <Finding EcinRecordID="1042893"> <Name>Goal Length of Stay for the ORG</Name> <Selected Value="http://stackoverflow.com/questions/14491992/0" DisplayValue="http://stackoverflow.com/questions/14491992/No"/> </Finding> <Finding EcinRecordID="1042894"> <Name>Goal Length of Stay for the GRG</Name> <Selected Value="http://stackoverflow.com/questions/14491992/1" DisplayValue="http://stackoverflow.com/questions/14491992/Yes"/> <NoteText>3 days</NoteText> </Finding></Findings>\[/code\]2 challenges:[*]Select node value of Findings/Finding/Name where Findings/Finding/Selected Value = "http://stackoverflow.com/questions/14491992/1"[*]Select node value of Findings/Finding/NoteText where Findings/Finding/Selected Value = "http://stackoverflow.com/questions/14491992/1"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 = 'http://stackoverflow.com/questions/14491992/1', but can't seem to assign the corresponding Name value in the Select statement.\[code\]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)\[/code\]Thanks!
 
Back
Top