Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6358591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:24:23+00:00 2026-05-24T23:24:23+00:00

I am unable to write a stored procedure for bulk insertion into my table.

  • 0

I am unable to write a stored procedure for bulk insertion into my table.

I want to insert list of <ObjectID> into [tbl_ReleaseHistory] keeping <FeatureID> null.

Also while inserting <FeatureID> into the same table <ObjectID> should remain null.

I am able to accomplish only the insertion of first <ObjectID> and <FeatureID> i.e 2218 and 67 from the xml passed for dummy execution.

Now how to iterate list of <objectID> for insertion?

So Is there any other method?

How to perform Bulk insert using XML?

CREATE PROCEDURE [dbo].[spVersionAddReleaseHistory] @ApplicationMaster NTEXT
AS
/****************************************************************************         
  DESCRIPTION:         
  ------------         
  This script is used to insert new record to the table tbl_VersionMaster.  
  MAINTENANCE LOG:         
  DATE          AUTHOR             DESCRIPTION         
  ----          ------             -----------         
  01/07/2011    Isha                  Initial Creation 

      /*DUMMY EXECUTION :  */ 
      DECLARE         @return_value int
      EXEC            @return_value = [dbo].[spVersionAddReleaseHistory]
                              @ApplicationMaster = N'<Root><ApplicationEntity>
                                            <Id>0</Id>
                                            <versionId>0</versionId>
                                            <Versions>
                                                <Version>
                                                  <Application>1111</Application>
                                                  <Version>11.11.123.123</Version>
                                                  <VersionMajor>11</VersionMajor>
                                                  <VersionMinor>11</VersionMinor>
                                                  <VersionBuild>123</VersionBuild>
                                                  <VersionRevision>123</VersionRevision>
                                                  <VersionFeatureIdList>
                                                      <FeatureID>67</FeatureID>
                                                      <FeatureID>68</FeatureID>
                                                      <FeatureID>69</FeatureID>
                                                  </VersionFeatureIdList>
                                                  <VersionObjectIdList>
                                                      <ObjectID>2218</ObjectID>
                                                      <ObjectID>2219</ObjectID>
                                                      <ObjectID>2220</ObjectID>
                                                      <ObjectID>2221</ObjectID>
                                                      <ObjectID>2222</ObjectID>
                                                      <ObjectID>2223</ObjectID>
                                                      <ObjectID>2224</ObjectID>
                                                      <ObjectID>2225</ObjectID>
                                                      <ObjectID>2226</ObjectID>
                                                      <ObjectID>2227</ObjectID>
                                                      <ObjectID>2228</ObjectID>
                                                      <ObjectID>2229</ObjectID>
                                                  </VersionObjectIdList>
                                                  <Components>
                                                      <Component>2218-Cmpjhhghghjghjg</Component>
                                                      <Component>2219-NEW </Component>
                                                      <Component>2220-OLD</Component>
                                                  </Components>
                                                  <Tables>
                                                      <Table>2221-t</Table>
                                                      <Table>2223-ty</Table>
                                                  </Tables>
                                                  <StoredProcedures>
                                                      <StoredProcedure>2226-tr</StoredProcedure>
                                                      <StoredProcedure>2227-trigr</StoredProcedure>
                                                  </StoredProcedures>
                                                  <Triggers>
                                                      <Trigger>2226-tr</Trigger>
                                                      <Trigger>2227-trigr</Trigger>
                                                  </Triggers>
                                                  <Features>
                                                      <Feature>2224-ffu</Feature>
                                                      <Feature>2225-ffffu</Feature>
                                                  </Features>
                                                </Version>
                                            </Versions>
                                          </ApplicationEntity></Root>'
   SELECT        'Return Value' = @return_value

  ****************************************************************************/ 
      DECLARE     @hDoc INT
      EXEC        Sp_xml_preparedocument
                  @hDoc                         OUTPUT,
                  @ApplicationMaster

       -- SET identity_insert tbl_versionmaster ON
      DECLARE @mylastident AS int

    SET @mylastident = (SELECT max(VM_VersionId) from [tbl_VersionMaster])
      BEGIN 
                  INSERT INTO [tbl_ReleaseHistory]
                        (     [RL_VersionId]          ,
                              [RL_ObjectId]           ,
                              [RL_FeatureId]
                        )
                  SELECT      
                              @mylastident            ,
                              ObjectID                ,
                              NULL
                  FROM OPENXML(@hDoc,'Root/ApplicationEntity/Versions/Version/VersionObjectIdList',2)
                  WITH(
                              ObjectID          INT   ,
                              FeatureID         INT
                        ) xmlitems
      END

      BEGIN
                   INSERT INTO [tbl_ReleaseHistory]
                                          (     [RL_VersionId]          ,
                                                [RL_ObjectId]           ,
                                                [RL_FeatureId]
                                          )
                    SELECT    
                                                @mylastident            ,
                                                NULL                  ,
                                                FeatureID
                    FROM OPENXML (@hDoc,'Root/ApplicationEntity/Versions/Version/VersionFeatureIdList',2)
                    WITH                  (
                                                ObjectID          INT   ,
                                                FeatureID         INT
                                          ) xmlitems
      END 
      SET NOCOUNT OFF;
      EXEC Sp_xml_removedocument @hDoc  

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:24:24+00:00Added an answer on May 24, 2026 at 11:24 pm

    Not 100% sure that I understand what you’re trying to do…. but assuming this is your XML file:

    DECLARE @Input XML 
    SET @Input = '<Root>
                     <ApplicationEntity>
                        <Id>0</Id>
                        <versionId>0</versionId>
                        <Versions>
                           <Version>
                              <Application>1111</Application>
                              <Version>11.11.123.123</Version>
                              <VersionMajor>11</VersionMajor>
                              <VersionMinor>11</VersionMinor>
                              <VersionBuild>123</VersionBuild>
                              <VersionRevision>123</VersionRevision>
                              <VersionFeatureIdList>
                                 <FeatureID>67</FeatureID>
                                 <FeatureID>68</FeatureID>
                                 <FeatureID>69</FeatureID>
                              </VersionFeatureIdList>
                              <VersionObjectIdList>
                                 <ObjectID>2218</ObjectID>
                                 <ObjectID>2219</ObjectID>
                                 <ObjectID>2220</ObjectID>
                                 <ObjectID>2221</ObjectID>
                                 <ObjectID>2222</ObjectID>
                                 <ObjectID>2223</ObjectID>
                                 <ObjectID>2224</ObjectID>
                                 <ObjectID>2225</ObjectID>
                                 <ObjectID>2226</ObjectID>
                                 <ObjectID>2227</ObjectID>
                                 <ObjectID>2228</ObjectID>
                                 <ObjectID>2229</ObjectID>
                              </VersionObjectIdList>
                              .... (more stuff - not relevant here) ....
                           </Version>
                        </Versions>   
                     </ApplicationEntity>
                  </Root>'
    

    you could easily select all ObjectID values using the SQL Server 2005 XQuery features (much easier to use than the old openxml stuff):

    SELECT
        V.VOI.value('(.)[1]', 'int')
    FROM
        @Input.nodes('/Root/ApplicationEntity/Versions/Version/VersionObjectIdList/ObjectID') V(VOI)
    

    or the list of the feature ID’s :

    SELECT
        F.FID.value('(.)[1]', 'int')
    FROM
        @Input.nodes('/Root/ApplicationEntity/Versions/Version/VersionFeatureIdList/FeatureID') F(FID)
    

    Now what do you want to do with those values??

    Update: OK, so to insert the values, use this statement:

    INSERT INTO dbo.tbl_ReleaseHistory(RL_VersionId, RL_ObjectId, RL_FeatureId) 
       SELECT
            V.VOI.value('(.)[1]', 'int'),
            (some value for RL_ObjectId),
            (some value for RL_FeatureId)
       FROM
           @Input.nodes('/Root/ApplicationEntity/Versions/Version/VersionObjectIdList/ObjectID') V(VOI)
    

    and similarly for the features, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying hard to write a stored procedure in ISeries DB2 but
I am using SqlBulkCopy object to write a datatable into an sql server table.
I want to dump the return into datagrid of silverlight application. I wrote a
I want to write a simple Outlook 2007 AddIn that allows me to manually
I am reading a tutorial on how to insert and update data into a
I'm trying to pass Japanese characters to a stored procedure in SQL Server. The
I want to make an Applet write to a text file. I think have
I ran into ss64.com which provides good help regarding how to write batch scripts
I'm trying to write a re-usable .NET Assembly that implements WCF. My current problem
Unable to find a SQL diff tool that meets my needs, I am writing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.