Total Pageviews

2015/11/16

[SQL Server] Year function

Problem
Here is my table schema in Microsoft SQL Server. If I would like to retrieve an integer that represents the year of the STA_DATE (with datetime data type).


How-To
We can use YEAR function, Microsoft SQL Server build-in function, to fulfill this requirement.
SELECT sta_date,
       year(sta_date) YEAR
FROM dbm034fa

Check the result :


Reference
[1] https://msdn.microsoft.com/en-us/library/ms186313.aspx



No comments: