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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL To Loop thru Table and set a calc value on every record

Status
Not open for further replies.

williadn48

Programmer
Oct 27, 2006
29
US
How do I loop thru a table and set a calculated value on every record?

Do While Not EOF
Read First Record
set intField = DateDiff(Second,Date1Fld,Date2Fld)
Next Record
Loop

Syntax please.
Thanks.
 
UPDATE <table Name>
SET <field name> = DATEDIFF(SECOND, Date1, Date2)
 
Lamprey is right - use a set-based stament such as he/she provided. Never loop through data; get the whole idea of looping through data out of your head - it is a very bad practice.

Actaully there are few rare cases where looping is necessary but at the beginner level you should never ever do a loop. Updates, inserts and delees can all be done more efficiently without looping.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top