Yogesh Bhadauriya's Blog

Do what ever you Like!

How to insert multiple record using xml in sql server 2005+

How to insert the multiple record using the xml into sql server, please check the following example.

DECLARE @idoc int

DECLARE @doc varchar(max)

SET @doc =’

<ROOT>

TransId=”1″ Add=”false” Edit=”true” Delete=”true” View=”true” Block=”false”>

</ROOT>’

–Create an internal representation of the XML document.

EXEC sp_xml_preparedocument @idoc OUTPUT, @doc

– Execute a SELECT statement that uses the OPENXML rowset provider.

SELECT * Into #TempTable

FROM OPENXML

(@idoc, ‘/ROOT/Trans’,1)

WITH (

TransId varchar(10),

[Add] bit,

Edit bit,

[Delete] bit,

[View] bit,

Block bit )

Select * From #TempTable

– drop temp table

drop table #TempTable

happy coding
Advertisement

April 16, 2011 - Posted by | Asp.net

1 Comment »

  1. thanx …..

    Comment by ravindra | July 5, 2011 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.