I have a XML as below in one of the table column of type xml
<fields>
<field>
<name>SourceFileName</name>
<value>ABCD</value>
</field>
<field>
<name>Template</name>
<value>XYZ</value>
</field>
</fields>
I need to query the XML to get the value for a specific text in field/name node
i used the below SQL but it doesn't return any data for the second one
SELECT *
FROM xmltable
WHERE XMLText.value('(/fields/field/name)**[1]**' ,'varchar(max)') LIKE
'Template'
SELECT *
FROM xmltable
WHERE XMLText.value('(/fields/field/name)**[1]**' ,'varchar(max)') LIKE
'SourceFileName'
whereas the below returns data
SELECT *
FROM xmltable
WHERE XMLText.value('(/fields/field/name)**[2]**' ,'varchar(max)') LIKE
'Template'
Can somebody help, how do i write a generic query to return data based on the name passed?
