Reputation: 579
I have a table similar to the below
Date | Year
2015-03-01 00:00:00:00 NULL
2014-01-02 00:00:00:00 NULL
I am trying to write a statement that would extract the year from the DateTime column Date, and place it in the nvarchar(4) column of Year.
The expected result would be:
Date | Year
2015-03-01 00:00:00:00 2015
2014-01-02 00:00:00:00 2014
Upvotes: 1
Views: 204
Reputation: 2376
You cna make use of the DATEPART
function here to extract the Year
.
update table set year = DATEPART(Year, Date)
Upvotes: 0
Reputation: 7344
update table
set [year] = year([Date])
SQL Server has a Year function which returns the year (as an int) of the date you apply it to.
Upvotes: 4