WHERE YEAR(DATE)

Database

WHERE YEAR(DATE)

Can't find a solution to this anywhere...

 

So a co-worker created a query with a where clause of....

 

WHERE AccountingMonth >= (((YEAR(DATE)-1)*12)+1)

It works when they run it and also when another co-worker runs it. But when I try to run it I get this error...

SELECT Failed: 3706: Syntax error: expected something between "(" and the "YEAR" keyword

 

Even when I reduce the statement to...

WHERE AccountingMonth >= YEAR(DATE)

It still does not work. Is there some type of reference library in Teradata (as there is in Excel VBA)? Sorry new to Teradata and can't figure out why it won't work for me.

2 REPLIES
N/A

Re: WHERE YEAR(DATE)

YEAR(DATE) is not a valid function in Teradata SQL, it's ODBC-SQL which might be automatically translated by older ODBC drivers (and based on some settings).

 

Simply use Standard SQL EXTRACT(YEAR FROM DATE) instead.

Teradata Employee

Re: WHERE YEAR(DATE)

Regarding the reference library: there is more information than you will ever want to know at info.teradata.com.  For this one in particular, on the left side of the screen you could select Teradata Database, Tools and Utilities Release: 15.10 (or whatever your release is), then go to SQL Reference / SQL Functions ... / DateTime and Interval Functions and Expressions.  Alternatively, you can click Teradata Database 16.0 on the right and then download all the SQL Reference PDFs.