Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I have 2 columns in my db named CreatedOn and TrainingExp

I want to write a query in such a way that my TrainingExp column has to be updated by adding 1 year to the CreatedOn column



How can i do that??

Any help is kindly appreciated
Posted

Try:
SQL
INSERT INTO myTable (CreatedOn, TrainingExp) VALUES (GETDATE(), DATEADD(year, 1, GETDATE()))
 
Share this answer
 
Comments
Perfect.....
Saumyavemula 20-Jan-12 2:57am    
Values are already inserted into table, i just need to update the column
OriginalGriff 20-Jan-12 3:10am    
Then replace the INSERT statement with an UPDATE, and replace GETDATE with the appropriate existing column value...
Saumyavemula 20-Jan-12 4:37am    
wrote this query but asking for parameter
Update Master set TrainingExp = dateadd("yyyy",1,[CreatedOn])

please help.....
OriginalGriff 20-Jan-12 4:42am    
I just tried it - it works fine for me. Check your Table/Field names and datatypes.
This is the Query you wanted -

SQL
UPDATE myTable set TrainingExp = DATEADD(year, 1, CreatedOn)
 
Share this answer
 
Comments
Saumyavemula 20-Jan-12 4:35am    
did the same but is asking for parameter to pass, whereas i need to change the whole column
It is working fine in my case.
Which database you are using??; SQL Server or MYSQL or any other please mention it...
Saumyavemula 20-Jan-12 4:47am    
i am using access database
I think the problem is "CreatedOn column is text".
So you need to convert it to datetime, then you can manipulate it.
I am searching for the same. If I find it, will let you know..
Go for the discussion -

http://p2p.wrox.com/access-vba/11341-convert-text-date-time-access.html

May you find anything useful.
Hi Saumyavemula,
Here is the solution for you.
UPDATE [Table name] set [column name] = DateAdd("yyyy, 1, Date())

You can add where clause to edit specific row.



Thanks,
Javed
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900