Error in using YEAR function in SQL Worksheet
AnsweredIn Datameer, how do you capture the year of a DATE column in a SQL worksheet?
This query
SELECT YEAR(rslt_part.draw_date) AS YEAR, COUNT(*) AS CT FROM
rslt_part
GROUP BY YEAR
is returning the following error: "Encountered 'AS YEAR'... was expecting one of: <EOF> "ORDER" ... "LIMIT" ... "OFFSET" ... "FETCH" ... "FROM" ... "," ... "AS" <IDENTIFIER> ... "AS" <QUOTED_IDENTIFIER> ... "AS" <BACK_QUOTED_IDENTIFIER> ... "AS" <BRACKET_QUOTED_IDENTIFIER> ... "AS" <UNICODE_QUOTED_IDENTIFIER> ... "UNION" ... "INTERSECT" ... "EXCEPT" ... "MINUS" ... "NOT" ... "IN" ... "<" ... "<=" ... ">" ... ">=" ... "=" ... "<>" ... "!=" ... "BETWEEN" ... "LIKE" ... "SIMILAR" ... "+" ... "-" ... "*" ... "/" ... "%" ... "||" ... "AND" ... "OR" ... "IS" ... "MEMBER" ... "SUBMULTISET" ... "CONTAINS" ... "OVERLAPS" ... "EQUALS" ... "PRECEDES" ... "SUCCEEDS" ... "IMMEDIATELY" ... "MULTISET" ... "[" ... "FILTER" ... "OVER" ..."
This has also been posted here:
https://stackoverflow.com/questions/57313724/capturing-year-of-a-date-in-sql-worksheet-datameer
-
Hi Rick,
You're correct, YEAR is a reserved word. You can find information about using reserved words as well as a link to Microsoft's documentation for the Transact-SQL specification we follow here:
If you have any further questions, don't hesitate to ask!
Please sign in to leave a comment.
Comments
2 comments