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

  • Home
  • SEARCH
  • 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 1066835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:04:23+00:00 2026-05-16T20:04:23+00:00

I have a stored proc that does inserts of people. I have an xml

  • 0

I have a stored proc that does inserts of “people”. I have an xml document with a bunch of people I want to insert. I want to call my stored proc like below and expect the stored proc to be called for each person in the xml. It is telling me that the stored proc “expects a parameter of @Id” and is failing. @Id is the first param and it appears that my syntax is not allowed. Is there a way to do this without iterating over each person in a cursor? I am using SQL Server 2005.

EXEC Stored_Procedure_That_Inserts_People
SELECT Node.value('Id[1]', 'Int') AS Id
,Node.value('FirstName[1]', 'varchar(50)') AS FirstName
,Node.value('LastName[1]', 'varchar(50)') AS LastName
,Node.value('MI[1]', 'char(1)') AS MI
FROM @PeopleXML.nodes('/ArrayOfPeople/Person') TempXML (Node)

For anybody interested, this is how I implemented my solution based on Tom’s answer below:

CREATE PROCEDURE [dbo].[ccIU_PersonBulkImport] 
(   
    @PersonXML as xml
)
AS
BEGIN

    SET NOCOUNT ON

    DECLARE 
    @LastName AS varchar(50),
    @FirstName AS varchar(50),
    @MI AS char(1)

        DECLARE People CURSOR FORWARD_ONLY STATIC READ_ONLY FOR 
                SELECT 
                Node.value('FirstName[1]', 'varchar(50)') AS FirstName
                ,Node.value('LastName[1]', 'varchar(50)') AS LastName
                ,Node.value('MI[1]', 'char(1)') AS MI
                FROM @PersonXML.nodes('/ArrayOfPeople/Person') TempXML (Node)

        OPEN People;
        FETCH NEXT FROM People INTO @FirstName,@LastName,@MI
        WHILE (@@FETCH_STATUS = 0)
        BEGIN
            EXEC domIU_People @FirstName,@LastName,@MI -- second stored proc that inserts or updates the person
            FETCH NEXT FROM People INTO @FirstName,@LastName,@MI;
        END
    CLOSE People;
    DEALLOCATE People;

END
  • 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-16T20:04:24+00:00Added an answer on May 16, 2026 at 8:04 pm

    No.

    You cant iterate a stored procedure like that generally they can only take objects as parameters the exception being a table object.

    In this example SQL will try and call the SP and then run the select as separate events which is why you are getting the error about the missing parameter.

    Your choices are to iterate through the XML and call the SP for each record, refactor the SP to either work using the XML as a separate parameter and break it down in the insert people procedure or refactor the code from the sp into the XML handling logic procedure.

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

Sidebar

Related Questions

Say i have a stored proc that inserts some data into a table. If
I have a stored proc select statement that lookes like that: SELECT p.ID AS
I have a stored proc that processes a large amount of data (about 5m
I have a Stored Proc that do a validation on a parameter ex. IF
So I have a Sybase stored proc that takes 1 parameter that's a comma
I have a SQL Insert query inside a stored proc, for inserting rows into
I have an xml in which i have stored some html under comments like
I have to convert a MSSQL stored proc that passes a varchar that is
I have a stored procedure that gives a friendly enough error that I want
I have a T-SQL stored proc that supplies a good amount of data to

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.