How do I insert output from xml.nodes() into a table?

link_cc

New Member
I am new to sql server and I am trying to insert rows into a database from XML documents. I have done some research and managed to get XML into a rowset using the XML nodes function. However, I have no idea what to do next. How do I insert this rowset into an existing table with the same column names?Below is what I have so far, can anyone help with where I go next?\[code\]DECLARE @xml xmlSET @xml = N' <Products> <Product> <id>4</id> <name>Amy</name> <age>25</age> </Product> <Product> <id>7</id> <name>Vicky</name> <age>40</age> </Product> </Products>'SELECT doc.col.value('id[1]', 'nvarchar(10)') id , doc.col.value('name[1]', 'varchar(100)') name , doc.col.value('age[1]', 'nvarchar(10)') age FROM @xml.nodes('/Products/Product') doc(col)\[/code\]
 
Back
Top