开发者

Teradata - Invalid Date supplied for FIELD

开发者 https://www.devze.com 2023-01-18 03:54 出处:网络
I\'m trying to query a table that has a varchar(100) \"VALUE\" column. This column can hold anything from a letter, a number or, in this case, a date.

I'm trying to query a table that has a varchar(100) "VALUE" column. This column can hold anything from a letter, a number or, in this case, a date.

The date will always be entered in the table as 'YYYY-mm-dd'. However, when I run the following query:

select * from myTable
where VALUE =  '2009-12-11' (Date, Format 'yyyy-mm-dd')  

I receive the following error:

Invalid date supplied for myTable.VALUE.

Example of the value table: (1,'122') (2,'red') (3,'2009-12-11')

Any ideas as to what might be causing this?

Thanks!开发者_如何学编程


if the data type is declared as varchar, it should just treat it like a string. try not specifying anything about the date format, like

select * from myTable
where VALUE =  '2009-12-11'


If you run an explain on the query, you can see that it's casting value to date before comparing against your supplied value. If you have another column that accurately records the type of what's in VALUE, you can add that to the where clause and you will no longer get the error (see below). Otherwise, go with Beth's recommendation.

select * from myTable
where VALUE =  '2009-12-11' (Date, Format 'yyyy-mm-dd')
and VALUE_TYPE = 'DATE';


Teradata internal date calculation is (year - 1900) * 10000 + (month * 100) + day.

So if date is 02/11/2009 (2nd November 2010) then

=(2009-1900) * 10000 + (11 * 100) + 2
=109 * 10000 + 1100 + 2
=1090000 + 1100 + 2    
=1090000
    1100
       2
----------
 1091102
----------

So 2nd november 2009 is stored in Teradata as 1091102. You can extract it in required format by casting (as u have it in varchar). Hope this helps.


Is it possible that VALUE is a reserved word in Teradata? If so, you need to put that into double quotes:

select * 
from myTable
where "VALUE" = '2009-12-11'
0

精彩评论

暂无评论...
验证码 换一张
取 消