Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI i have below xml string

<DefaultState>
       <state>FL</state>
       <State>CO</State>
   </DefaultState>
   <ID>kkkkk</ID>
using below query in sql server iam able to get the value in id but how can i get the multiple values of the default state in sql server please help in this regards

SQL
@ID=DTO.rows.value('ID)[1]','varchar(50)'),
FROM @ProjectXml.nodes('/Gain') DTO(rows)

<pre lang="HTML">
Posted
Updated 8-Jun-12 0:34am
v2

1 solution

Try this. Worked for me

SQL
DECLARE @xmlVal as XML


SET @xmlVal ='<gain><defaultstate>
       <state>FL</state>
       <state>CO</state>
   </defaultstate>
   <id>kkkkk</id></gain>'


SELECT
Gain.DefaultState.value('../ID[1]','nvarchar(50)') Id,
Gain.DefaultState.value('state[1]','nvarchar(50)') State1,
Gain.DefaultState.value('State[1]','nvarchar(50)') State2
FROM
 @xmlVal.nodes('Gain/DefaultState') as Gain(DefaultState)




Hope this helps , If yes then plz accept and vote the answer. Any queries / questions on this are always welcome.

Thanks & Regards
RDBurmon.Sr.Software Engineer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900