title: Cursor with Stored Procedure Question
body: <p>I need to use a cursor to call a stored procedure that has 2 parameters that i need to pass into from Customers table.</p>
  <p>Here is what I mean;</p>
  <p>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]</p>
  <p>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.</p>
  <p>I have used sp_executesql, but not successfully.</p>
  <p>Here is what i have tried but not working.</p>
  <pre><code>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
  </code></pre>
  <hr />
  <p>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.</p>
  <h3>Update:</h3>
  <p>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.</p>