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 129941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:52:10+00:00 2026-05-11T05:52:10+00:00

I need to use a cursor to call a stored procedure that has 2

  • 0

I need to use a cursor to call a stored procedure that has 2 parameters that i need to pass into from Customers table.

Here is what I mean;

My goal is to pass all the CustomerID and CustomerName from Customers table into my stored procedure called AddCustomers which has 2 parameters of CustomerID and CustomerName. ie: AddCustomer [CustomerID],[CustomerName] [side note: this AddCustomer stored procedure does some filtering things that i need for my apps]

So the end result of using this CURSOR with an stored procedure is to DUMP/PASS all of customerID and CustomerName from Customers table into AddCustomer stored procedure.

I have used sp_executesql, but not successfully.

Here is what i have tried but not working.

Declare @CustomerID int Declare @CustomerName varchar(100)  Declare cur CURSOR READ_ONLY FOR SELECT CustomerID, CustomerName from Customers  OPEN cur  FETCH NEXT FROM cur INTO @CustomerID, @CustomerName  WHILE @@FETCH_STATUS = 0 BEGIN    EXEC AddCustomer @CustomerID, @CustomerName     FETCH NEXT FROM cur    INTO @CustomerID, @CustomerName END  CLOSE cur DEALLOCATE cur 

I am new to the use of cursors so I am not sure why this isn’t working. If you can provide any clues or links, I’d would appreciate it.

Update:

OK, if Cursor CANNOT loop thru stored procedure, THEN can anyone provide a solution or hints to my problem, which is to PASS all CustomerID and CustomerName from Customers table into my AddCustomer stored procedure so that i can do some filtering stuff on each of the CustomerID and CustomerName that i pass into AddCustomer Stored procedure.

  • 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. 2026-05-11T05:52:11+00:00Added an answer on May 11, 2026 at 5:52 am

    Sam,

    There are times when using a stored procedure to do a task like this is perfectly appropriate. Le Dorfier has certainly given me lots of good advice but I have to disagree with him on this one. Especially if this is a one-time processing of your records to achieve some form of transformation, then you are really close to your solution as I don’t see any obvious flaws in your code. BTW, I’ve taken the same approach on more than one occasion and it has worked very well.

    So…post the stored procedure as well as we’ll see if that doesn’t help. Also, what specific error are you seeing?

    UPDATE: Wait, are you just running this in the SQL Window? I usually package this stuff up in another stored procedure (often just a temporary one) and then run it. Of course, it may also be that you just need to execute this code – not using EXEC but just using the Execute button…it is hard to tell based on your description.

    UPDATE 2: You say above that the error is something about the table. Are you sure that the data types that you have defined are correct? Could the error be a mismatch between the data pulled from the table and the type of the var into which you are placing it?

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

Sidebar

Related Questions

I am loading some data into a temp table. I then use a cursor
SQL Table How to pick duplicate records, do i need to use cursor ???
I need to call some Stored Procedures from Delphi and because they are related
I read somewhere that 99% of time you don't need to use a cursor.
I'm not sure when it is appropriate to use a cursor. I need to
I need use this method with three distinct classes: Orders, Customers, Suppliers public void
I need to use the objdump and readelf commands in my application that runs
I need to show more than one result from each field in a table.
I'm trying to make a MySQL stored procedure and I need to know how
Due to a legacy report generation system, I need to use a cursor 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.