Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Using OPENXML in stored Procedure

Using OPENXML in stored Procedure

Scheduled Pinned Locked Moved Database
databasesharepointsql-serversysadminxml
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    meeram395
    wrote on last edited by
    #1

    I have a set of records which I want to insert to the table at one stretch. For this, I am using OpenXML keyword in Sql Server 2005. Following is my stored procedure:

    ALTER procedure [dbo].[usp_InsertManyRows]

    @XMLDOC xml

    AS
    declare @xml_hndl int

    exec sp_xml_preparedocument @xml_hndl OUTPUT, @XMLDOC

    Insert Into outputfiles
    (

            Processid
    
            )
    

    Select

            Processid
    

    From
    OPENXML(@xml_hndl, '/Process/ProcessId')
    With
    (

                        Processid int '/Process/ProcessId'
    
                        )
    

    The table 'OuputFiles' contains column ProcessId, OutputFileName and ContributionFileName columns. When I tried to test the sp as below, it was inserting the same record multiple times. I am not sure why it is:

    exec usp_InsertManyRows '<Process><ProcessId>8712</ProcessId><ProcessId>14444</ProcessId></Process>'

    It is only inserting 8712 two times, not at all 14444. I am using this for the first time. Please help me how to resolve this, as well as inserting the values for multiple columns like OutputFileName and ContributionFileName columns. Thanks in advance

    Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

    G 1 Reply Last reply
    0
    • M meeram395

      I have a set of records which I want to insert to the table at one stretch. For this, I am using OpenXML keyword in Sql Server 2005. Following is my stored procedure:

      ALTER procedure [dbo].[usp_InsertManyRows]

      @XMLDOC xml

      AS
      declare @xml_hndl int

      exec sp_xml_preparedocument @xml_hndl OUTPUT, @XMLDOC

      Insert Into outputfiles
      (

              Processid
      
              )
      

      Select

              Processid
      

      From
      OPENXML(@xml_hndl, '/Process/ProcessId')
      With
      (

                          Processid int '/Process/ProcessId'
      
                          )
      

      The table 'OuputFiles' contains column ProcessId, OutputFileName and ContributionFileName columns. When I tried to test the sp as below, it was inserting the same record multiple times. I am not sure why it is:

      exec usp_InsertManyRows '<Process><ProcessId>8712</ProcessId><ProcessId>14444</ProcessId></Process>'

      It is only inserting 8712 two times, not at all 14444. I am using this for the first time. Please help me how to resolve this, as well as inserting the values for multiple columns like OutputFileName and ContributionFileName columns. Thanks in advance

      Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

      G Offline
      G Offline
      Goutam Patra
      wrote on last edited by
      #2

      You can try like the following For SQL

      Select
      Processid
      From
      OPENXML(@xml_hndl, 'root/Process')
      With
      (
      ProcessId int

      )

      Use XML as

      '<root><Process ProcessId="8712"></Process> <Process ProcessId="1424"></Process></root>'

      Look http://msdn.microsoft.com/en-us/library/aa276847%28SQL.80%29.aspx[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups