Hi everyone, this is my first time using this site.
OK, 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.