SQL: Inserting hierarchical data from XML

Joined
Jan 7, 2009
Messages
1
Reaction score
0
Hi there

I have a problem here with the SQL query. I get a parameter @xmlObject of ntext type which contains the data objects in xml format. Like this:

<Employees>
<Employee EmployeeID="1" Name="John">
<Properties>
<Property EmployeeID="1" PropertyID="1" Value="age">
</Property>
<Property EmployeeID="1" PropertyID="2" Value="height">
</Property>
</Properties>
</Employee>
<Employee EmployeeID="2" Name="Karen">
<Properties>
<Property EmployeeID="2" PropertyID="1" Value="weight">
</Property>
</Properties>
</Employee>
</Employees>

(It is just an example, so don't pay attention to the contents only the structure).
As you can see each "Employee" object has a group of sub-objects of the type "Property". What I am trying to do is to insert all this data (the collection) in one go to the database. But the table Employee has a column EmployeeID which is an identity column (I don't insert the coming EmployeeIDs, they are generated automatically). So the question is - how to insert both Employees and their Properties with the correct ID references.

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top