How to fetch a value from a column which contains XML in SQL Server? below is my sample XML column value and the id's can be swap anytime(101,100) or (201,100,101,321).
<Questions>
<item id="101">Yes</item>
<item id="100">No</item>
</Questions>
I want to fetch a value based on Id. Like fetching Yes
from id=101
.
Sample code much appreciated.
I tried with below sample, but Unable to retrieve value "Yes"
select Y.value('@item[1]','varchar[3]') as valT from tbl_storeXML s cross apply s.Questions.nodes('Questions/item') as X(Y) where e.empId=256 and Y.value('@id','int')=101
Please help on this. Ps. It's not a home work, I am learning handling xml in sql server.