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 |
shafiqkr
Starting Member
7 Posts |
Posted - 2011-12-15 : 08:27:32
|
i want to save xml data into a table in sp,passed as string,here is my codealter PROCEDURE usp_be_insertXML -- Add the parameters for the stored procedure here@xml varchar(1000) ASBEGINDECLARE @idoc intDECLARE @doc varchar(1000)SET NOCOUNT ON;EXEC sp_xml_preparedocument @idoc OUTPUT, @xmlBEGIN TRY INSERT INTO testing ([Name] ,[Fname] )SELECT Column1,Column2FROM OPENXML (@idoc, 'NewDataSet/Sheet1', 1)WITH ([Column1] [nvarchar](50),[Column2] [nvarchar](50))END TRYBEGIN CATCHEND CATCHEXECUTE sp_xml_removedocument @idocENDThis inserts NULL only in table,any help? and here is XML<NewDataSet> <Sheet1> <Column1>Name</Column1> <Column2>Fname</Column2> </Sheet1> <Sheet1> <Column1>khan</Column1> <Column2>dd</Column2> </Sheet1> <Sheet1> <Column1>mytest</Column1> <Column2>ff</Column2> </Sheet1> </NewDataSet> |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-15 : 09:07:03
|
make the proc like belowalter PROCEDURE usp_be_insertXML -- Add the parameters for the stored procedure here@xml xmlASINSERT INTO testing ([Name] ,[Fname] )select t.u.value('(./Column1)[1]','varchar(100)') ,t.u.value('(./Column2)[1]','varchar(100)') from @xml.nodes('/NewDataSet/Sheet1[position()>1]')t(u)GO ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|