sql server - XPATH Get list item with ID held in sibling -
To use XPath in T-SQL, I am trying to get an attribute value from the option list where the ID is to select the correct list. I / O
Any help would be appreciated.
inserted into my mytable table (pk int primary key identification (1,1), myXML xml) into the @myTable values ('Fields & gt; & lt; Field ID = " 1111 "& gt; Details & gt; Now Brown Cow & lt; / description & gt; value & gt; 3 & lt; / pricing & gt; & lt; option & gt; & lt; Option & gt; Option; OptionContent = "Select one" OptionID = "- 1" /> Option Option OptionContent = "Pluto" optionID = "2" /> option> OptionContent = "Saturn" optionID = "3" /> gt; & lt; / option & gt; & lt; / Field & Lt; Field ID = "2222" & gt; & lt; Details & gt; Foo Bar & lt; / descript ion & gt; & lt; VALUE & gt; 2 & lt; / pricing & gt; LT; Option & gt; Option & gt; Option & gt; Option & lt; Option OptionContent = "Select one" OptionID = "- 1" /> Option & lt; Option OptionContent = "Water" OptionID = "3" /> & Lt; Option OptionContent = "juice" OptionID = "4" /> & Lt; OptionContent = "Water" OptionID = "5" /> & Lt; / Options & gt; & Lt; / Options & gt; & Lt; / Field & gt; & Lt; / Fields & gt; ') As myfield.ref.value (' @ id ',' small mark ') as my [id], myField.ref.value (' (. / Description) [1] ',' Navarrek (10) '). ') Choose [description], MyField.ref.value (' (./pay) [1] ',' int ') as [value], myField.ref.value (' (./options / options / options [@OptionID = "- 1"] / @OptionContent [1] MyField cross_myTable cross c.myXML.nodes (apply '/ fields / fields') from [selectedDescription] as ',' nvarchar (10)) (References)
id details value actual approximate ----------------- -------- ------ -------- -------- 1111 Now, Br3, tap Saturn 2222, Fu Bar, 2 tap.
change
(./options / options / Option [@OptionID = "- 1"] / @ option content) [1]
$ id go to: = ./Value[1 ] Return (./Options/Options/Option[@OptionID=$id]/@OptionContent)[1]
Your query should be
MyField.ref.value ('@ id', 'small') as [id], myField.ref.value ('(. [Description], [value] as myField.ref.value ('(. /. Value) [1]', 'int'), as described in [description] [1] ',' nurturing (10) ' MyField.ref.value ('$ Id ID: = ./Value[1] Return (./Options/Options/Option[@OptionID=$id]/@OptionContent)[1]', 'nvarchar (10)) Apply [myname = 'Fields'] to MyField (referee)
Comments
Post a Comment