0
votes

When I try to import teradata data with a where in the sql statement I get the following error

clients<-dbGetQuery(con, "SELECT * from clients where year(cl_dataentrada) = 2018")

Error in new_result(connection@ptr, statement) : nanodbc/nanodbc.cpp:1344: 42000: [Teradata][ODBC Teradata Driver]Teradata DatabaseSyntax error: expected something between the 'where' keyword and the 'year' keyword.

clients<-data.frame(clients)

I've also tried:

clients<- dbSendQuery(con, "SELECT * from clients where year(cl_dataentrada) = 2018")

Error in new_result(connection@ptr, statement) : nanodbc/nanodbc.cpp:1344: 42000: [Teradata][ODBC Teradata Driver]Teradata DatabaseSyntax error: expected something between the 'where' keyword and the 'year' keyword.

Also in a sql chunk :

SELECT * from clients where year(cl_dataentrada) = 2018

Error in new_result(connection@ptr, statement) : nanodbc/nanodbc.cpp:1344: 42000: [Teradata][ODBC Teradata Driver]Teradata DatabaseSyntax error: expected something between the 'where' keyword and the 'year' keyword. Failed to execute SQL chunk

1
This could be a driver issue. Can you please try with Extract(year from cl_dataentrada). the function year is an odbc function not Teradata - so may be that is one of the reasons that is causing errorShiva Prakash

1 Answers

0
votes

As Shiva Prakash suggested this finally works:

clients<-dbGetQuery(con, "SELECT * from clients where extract(year from cl_dataentrada)=2018")

It was an error because the function year is an odbc function not Teradata. Thank you.