Please find below the script snippet
declare @xml xml
set @xml = '<Message>
<MessageData>
<MessageDataSet >
<id> 1 </id>
<name>Vasan</name>
</MessageDataSet>
<MessageDataSet >
<id> 2 </id>
<name>Vivek</name>
</MessageDataSet>
</MessageData>
</Message>'
SELECT
t.c.value('(id)[1]','varchar(100)')
from
@xml.nodes('/Message/MessageData/MessageDataSet') AS t(c)
I am getting all the 'id' node values, that is '1' & '2'. My need, I have to directly fetch the value of the second 'id', in this case.it will be '2'. Can anyone let me know the Select query syntax for the same? Thanks.