Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 adding a value to a date

Author  Topic 

InNomina
Starting Member

40 Posts

Posted - 2012-05-21 : 18:51:49
I need to take a date column in table 1 and add a number to the years i.e.
< TABLE 1-Column A "01/01/1980" + table 2 Column B "6" years = Table 1 Column B "01/01/1986"

Not sure how this would be done.

-------------------------
"If you never fail, you're not trying hard enough"

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-21 : 19:01:03
whats the column by which tables are related? Unless you have a relation, you wont be able to determine which row value needs to added to which row date

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

InNomina
Starting Member

40 Posts

Posted - 2012-05-21 : 19:20:23
TABLE 2 id is linked to the records in table 1

Example:

Table 1
ID | Date1 | ID of a record in Table 2| Date 2

Hope this is clear

-------------------------
"If you never fail, you're not trying hard enough"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-21 : 19:22:56
you mean this?

SELECT t1.*,DATEADD(yy,t2.ColB,t1.ColA) AS NewDate
FROM table1 t1
INNER JOIN Table2 t2
ON t2.ID = t1.ID


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

InNomina
Starting Member

40 Posts

Posted - 2012-05-21 : 19:49:00
I will give that a shot...Thanks!


-------------------------
"If you never fail, you're not trying hard enough"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-21 : 19:50:47
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -