SQL Server - Passing xml file as parameter to storedprocedure

Asked By Bharghavi ch on 12-Apr-11 10:11 AM
Hi friends,
I need  to pass the xml file as a parameter to the storedprocedure. It has to open that xml file and inserts that data from the xml file into a new temp table in the database.Please give me solution for this.
Thank you.
Peter Bromberg replied to Bharghavi ch on 12-Apr-11 12:43 PM
You need to study the syntax for OPENXML, which is found in SQL Server books online.
Jitendra Faye replied to Bharghavi ch on 13-Apr-11 01:31 AM
To pass the xml file as a parameter to the storedprocedure, you have to use openxml() in stored procedure-
use this procedure more that-

create procedure dbo.up_Insert_Company(@xmldata ntext)
as
begin
  declare @FileHandle int -- Filehandle to the xml stuff
  /* convert the xml data into a recordset */
  exec dbo.sp_xml_preparedocument @FileHandle output, @xmldata
  insert into dbo.categories
  select * from openxml(@FileHandle, '/record')
  with dbo.categories
end

/*
And here's how you execute the SQL...
*/
dbo.up_Insert_Company '<record CategoryName=''Sample Insert'' Description=''Testing'' />'

use this procedure and let me know.