Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to execute a sp in a loop?

Status
Not open for further replies.

aco636

IS-IT--Management
Nov 25, 2003
212
GB
Hi there

I am pretty used to writing vbScript to manage databases.
However SQL Stored Procs are pretty new to me. Any help gratefully received.

I would like to create a record set from a normal SELECT Statment (Will return about 3,500 records) and execute a script for each record.

EG:
SELECT SerialNo FROM ......

DO WHILE NOT RECORDSET.EOF (END OF FILE/LIST)
BEGIN TRAN
UPDATE & INSERT various
COMMIT
LOOP
 
Yes, you need to use a CURSOR. It allows you to 1st select the record you want to process as a driver and with a WHILE
Loop allows you to do whatever you want, eg. insert, update, delete, etc.

Remember when... everything worked and there was a reason for it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top