Logo 
Search:

C# Forum

Ask Question   UnAnswered
Home » Forum » C#       RSS Feeds

Retrieve values when getting xml as a input parameter in a stored procedures

  Asked By: Jayden    Date: Jul 07    Category: C#    Views: 1502
  

How to retrieve values , if you are getting xml as a input parameter in a stored procedures..

There are situations when we have to send xml as a input parameter, there are multiple ways to fetch values from xml..
Iam listing one of them

Take an example you are getting employee information in xml format
<Root>
<Employee Code="1">
<Name>Tim<Name>
</Employee>
<Employee Code="2">
<Name>Jimmy<Name>
</Employee>
</Root>

I want to retrieve Code and Name from Xml

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Freya Brown     Answered On: Jul 07

To retrive values  Employee Code & Name from xml...

Declare @tempEmp xml
set @tempEmp='<Root>
<Employee Code="1">
<Name>Tim</Name>
</Employee>
<Employee Code="2">
<Name>Jimmy</Name>
</Employee>
</Root>'

SELECT T.c.value('@Code','int'),T.c.value('Name[1]','VarChar(100)')
FROM @tempEmp.nodes('/Root/Employee') T(c)

 
This post is locked for further answers.




Tagged: