I’m dealing with an old database that contains records of 365 days of the past 3 years. I’m trying to get the 2016 records ‘for example’ and change the year to 2020 and then add my new record to the table so it would contain now records of 4 years. this is what I did so far :
SELECT DATEADD(YEAR , 2020- year(Date),Date) as Date_Modified,Date from Date
I want to make where
condition to specify the year is 2016 so it would update the records with the year 2016. how to do that ?? I tried where year()=2016
it was an error.
I appreciate any help.
Advertisement
Answer
Here is one more way to do it:
Insert into testT select DATEADD(YEAR , 2020- year(Date_c),Date_c) from testT where year(Date_c) = '2016'
This insert statement will take data that have date in year 2016 and insert them as year 2020.
Here is the DEMO
In this DEMO the example table is named testT
and your date column Date_c
. YOu can also see a elect statement that will return only the rows that have date in year 2016.