I have a Teradata table in tableau.
When I am trying to give
select * from table name where date = <parameter.date selector>
I see the error as
a character string failed conversation to a numeric value
Can someone assist me in solving this?
Related
I searched stackoverflow and on the internet but I could not find the exact answer. You can see my query below. I cannot figure out why I am getting the error message A character string failed conversion to a numeric value. I came to the conclusion it is that line of code because when I comment it out I don't get that error message but a different one. What I get instead is no more spool space which to me would make sense.
SELECT a.store_nbr AS club_number, a.visit_date, count(transaction_id)
FROM table_one
WHERE division = 1
AND a.visit_date BETWEEN '2020-01-01' AND '2020-02-01
I am trying to extract data based on a date condition connecting to SQL from R.
My database connection is from Impala.
Below is my sample code.
dbGetQuery(src,"SELECT * FROM sample WHERE eventdate BETWEEN '2017-01-31' AND DATEADD(m,1,'2017-01-31')")
I get below error while trying to query.
Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
Unable to retrieve JDBC result set for select * from sample where
eventdate between '2017-01-31' and dateadd(m,1,'2017-01-31') ([Cloudera]
[ImpalaJDBCDriver](500051) ERROR processing query/statement. Error Code: 0,
SQL state: TStatus(statusCode:ERROR_STATUS, sqlState:HY000,
errorMessage:AnalysisException: Could not resolve column/field reference: 'm'
), Query: select * from sample where eventdate between '2017-01-31' and dateadd(m,1,'2017-01-31').)
Instead of using DATEADD if I hard code between two dates I get the result e.g.
dbGetQuery(src,"SELECT * FROM sample WHERE eventdate BETWEEN '2017-01-31' AND '2017-02-28' LIMIT 5")
I get the result for above code but I want to use DATEADD in my code because I have multiple date conditions which I am doing using a loop function.
Any help regarding this please.
The problem is the format of your literal date string ('2017-01-31'). SQL Server, when passed a literal string for date for DATEADD will implicitly convert the value to a datetime. datetime will read the string in the format yyyy-dd-MM, translating the value to 20173101; you can see the problem there (there aren't 31 months in the year).
If you're using a literal string to pass a date(time) then use either the format yyyyMMdd or yyyy-MM-ddThh:mm:ss.sssssss as both are unambiguous regardless language and datatype.
So, for your value that would be:
WHERE eventdate BETWEEN '20170131' AND DATEADD(m,1,'20170131')
On a different note, are you really looking for rows between 20170131 and 20170228, inclusive of those dates (assuming eventdate is a date)?
remove time from your DATEADD function by using Convert function.
dbGetQuery(src,"SELECT * FROM sample WHERE eventdate BETWEEN '2017-01-31' AND convert(varchar,DATEADD(month, 1, '2017/08/25'),23)")
I'm trying to translate an varchar variable into a new variable with hashing function.
At some moment of processing it returns below error:
ERROR 6706: The string contains an untranslatable character.
How to make it ignore such cases i.e. return NULL values and keep translating?
I am just trying to add the letter A to the beginning of the results Im bring back and I keep getting this message.
Query Failed. 3535 a character string failed conversion to a numeric value
Thanks for any help.
select
a.area_cd as CO_Area
, 'A' + a.area_cd
from intDDt.DIXX a
+ is a numeric operator in Standard SQL and Teradata and not a string concat (as in MS SQL Server). You need to use || instead:
'A' || TRIM(a.area_cd)
The TRIM results in an automatic typecast.
please try this,
select
a.area_cd as CO_Area
, ('A' + CAST(a.area_cd AS VARCHAR))
from intDDt.DIXX a
I'm trying to run a simple query that works with MySQL or other MySQL connector API's,
SELECT * FROM `table` WHERE type = 'farmer'
I've tried various methods using the RMySQL package and they all get the same error
RS-DBI driver warning: (unrecognized MySQL field type 7 in column 1 imported as character)
Type = 'farmer'
(Query<-paste0("SELECT * FROM `table` WHERE type = '%",Type,"%'"))
res<-dbGetQuery(con, Query)
Query<-paste("SELECT * FROM `table` WHERE type = \'farmer\'")
Query<-paste("SELECT * FROM `table` WHERE type = 'farmer'")
What am I doing wrong?
"type" is a keyword in MYSQL. Surround the it with backticks to escape field names.
SELECT * FROM `table` WHERE `type` = 'farmer'
Also you probably have a time stamp column in your table. R is known to not recognize that column type. Convert it to a unix time stamp in the portion of the SQL statement.
Looks like the db schema has something in column which is of type 7 -- and that type appears to be unknown to the RMySQL driver.
I try to exclude column one in the query, or cast it at the select * ... level eg via something like
select foo as character, bar, bim, bom from 'table' where ...
To be clear, when I encountered this error message, it was because my data field was a time stamp.
I verified this by changing my query to SELECT created_at FROM ... which caused the error. I also verified this by changing the query not to include the column names that were timestamps, then I had no errors.
Note too, that the error message counts columns starting from 0 (instead of 1 as R does)
IMHO, the answer is you aren't doing anything wrong, but it's something that needs to be fixed in RMySQL.
The workaround is after you read in your data, you need to call one of the several possible character to datetime conversion functions. (Which one depends on what you want to do with the time stamp exactly.)