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

Increment date using loop

Status
Not open for further replies.

DH

Programmer
Dec 8, 2000
168
0
0
As an example, lets say I have the follwing exampleTable with 2 columns and data like so:

userId expirationDate
--------- --------------
8 6/05/2006
24 6/15/2006
30 6/22/2006

I would like to use the following WHERE clause to grab certain rows of data:

SELECT expirationDate
FROM exampleTable
WHERE userId IN (8,30)

How can I loop throught the results to UPDATE the expirationDate by 1 month for rows that match the WHERE clause?

I haven't used loops very much in SQL so thanks in advance for your help.

DH
 
No need for a loop here, how about:
Code:
Update exampleTable
Set expirationDate = dateadd(mm,1,expirationDate)
Where userID IN (8,30)

Jim
 
Awesome, works perfect! Thanks for your help 2night.

DH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top