Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ter1234
Starting Member
2 Posts |
Posted - 2010-07-29 : 07:16:48
|
| I am new to sql so sorry for the question i have a stored procedure that receives XML:@students XMLthat is like this<Students><Student><Name>O1</Name><ID>1</ID></Student><Student><Name>O2</Name><ID>2</ID></Student></Students>i have a table of studentswith ID column and name columnhow do i insert the xml into the table the nodes of studenst?sample code will be very helpfull... |
|
|
sql-programmers
Posting Yak Master
190 Posts |
|
|
ter1234
Starting Member
2 Posts |
Posted - 2010-07-29 : 07:25:39
|
| Thanks... can ypu pls show me how to do that i just dont understan this subject |
 |
|
|
sql-programmers
Posting Yak Master
190 Posts |
Posted - 2010-07-29 : 07:28:09
|
| CREATE TABLE #tblXML (ID INT PRIMARY KEY, xmlVal XML not null)declare @x as varchar(max)set @x='<Students><Student><Name>O1</Name><ID>1</ID></Student><Student><Name>O2</Name><ID>2</ID></Student></Students>'INSERT #tblXML VALUES(2, @x)SELECT x.query('ID').value('.','INT') as ID,x.query('Name').value('.','varchar(100)') as ProductFROM #tblXML CROSS APPLY xmlVal.nodes('/Students/Student') AS Tref(x)drop table #tblXMLSQL Server Programmers and Consultantshttp://www.sql-programmers.com/ |
 |
|
|
|
|
|