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

Update in sub query (dateadd)

Status
Not open for further replies.

TheJFM

Programmer
Jun 13, 2002
65
GB
Hi,

I have table A with an field (int) that hold values equating to dates.


e.g. 21456
21457

To get date values this is joined to table B

21465 2004-02-01
21457 2004-02-02

I need to update the field in table A so that the numeric value is equal to the date + 12 months.

How can I do this in a single update?

Thanks



** Don't reach for the moon when you have the stars. ;-) TheJFM **
 
Try something like this:

Code:
UPDATE Table_A SET int_field = int_field + your_calculation( Table_B.date  + 12 months )
FROM Table_A
    INNER JOIN Table_B ON Table_B.[ID] = Table_A.[ID]

Zhavic

---------------------------------------------------------------
In the 1960s you needed the power of two Comodore64s to get a rocket to the moon. Now you need a machine which is a vast number of times more powerful just to run the most popular GUI.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top