Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For example assuming your xml as below</p> <pre><code>&lt;StoredProcedure&gt; &lt;User&gt; &lt;UserName&gt;&lt;/UserName&gt; &lt;/User&gt; &lt;Profile&gt; &lt;FirstName&gt;&lt;/FirstName&gt; &lt;/Profile&gt; &lt;Address&gt; &lt;Data&gt;&lt;/Data&gt; &lt;Data&gt;&lt;/Data&gt; &lt;Data&gt;&lt;/Data&gt; &lt;/Address&gt; &lt;/StoredProcedure&gt; </code></pre> <p>this would be your stored procedure</p> <pre><code>INSERT INTO Users (UserName) SELECT(UserName) FROM OPENXML(@idoc,'StoredProcedure/User',2) WITH ( UserName NVARCHAR(256)) </code></pre> <p>where this would provide idoc variable value and @doc is the input to the stored procedure</p> <pre><code>DECLARE @idoc INT --Create an internal representation of the XML document. EXEC sp_xml_preparedocument @idoc OUTPUT, @doc </code></pre> <p>using similar technique you would run 3 inserts in single stored procedure. Note that it is single call to database and multiple address elements will be inserted in single call to this stored procedure.</p> <h3>Update</h3> <p>just not to mislead you here is a complete stored procedure for you do understand what you are going to do</p> <pre><code>USE [DBNAME] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[procedure_name] @doc [ntext] WITH EXECUTE AS CALLER AS DECLARE @idoc INT DECLARE @RowCount INT SET @ErrorProfile = 0 --Create an internal representation of the XML document. EXEC sp_xml_preparedocument @idoc OUTPUT, @doc BEGIN TRANSACTION INSERT INTO Users (UserName) SELECT UserName FROM OPENXML(@idoc,'StoredProcedure/User',2) WITH ( UserName NVARCHAR(256) ) -- Insert Address -- Insert Profile SELECT @ErrorProfile = @@Error IF @ErrorProfile = 0 BEGIN COMMIT TRAN END ELSE BEGIN ROLLBACK TRAN END EXEC sp_xml_removedocument @idoc </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload