Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

MS SQL Server execute stored procedure on each row

Is there a while statement to execute a stored procedure for each row in the returned data below?

SELECT   ReservationID
FROM     dbo.everyware_t_reservation
WHERE    DateModifiedEW > DATEADD(HH, -24, GETDATE())
         AND LEN(Phone1) + LEN(Email) > 0
         AND ISNULL(IndividualID, 0) + ISNULL(AltIndividualID, 0) = 0
ORDER BY DateModifiedEW DESC;


EXEC dbo.brkCreateLeadFromReservations  4631496

Open in new window

Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Give us the reason why you wish to execute a stored procedure on a Row By Agonizing Row basis, as T-SQL is a set based language and not optimized for single row processing.
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Larry Brister

ASKER

Well...
Data has been coming in from a customer for a year into a table

There is a stored proc I built that compares demographics and sees if the person is in our system or not and creates if needed

Gets the IndividualID (Our side)
And updates the inbound data record

Works fine on current data coming in

Its the HISTORY I need to run it against
Thanks.  And as a follow-up... this can't be done in a WHILE Statement?
this can't be done in a WHILE Statement?

it is using WHILE LOOP!

WHILE (Transact-SQL)
https://docs.microsoft.com/en-us/sql/t-sql/language-elements/while-transact-sql