I would like to convert a varchar(8) field to a date field in a select statement. I have tried a number of different statements and non of them seem to work. For the statements that I think should work, I keep getting the error message:
2666: Invalid date supplied for
The syntax I think should work is:
SELECT CAST(column_name AS DATE FORMAT 'YYYY-MM-DD') from databasename.tablename sample 10;
column_name is defined as varchar(8) in the source table.
Has anyone else run into this issue, and if so, were you able to solve?
Re: Convert varchar(8) to date in select statement
I just tried the following on Teradata 13.0;
create table TestCastDate (C01 Integer, C02 VarChar(8)); Insert Into TestCastDate values (1, '19981001'); Insert Into TestCastDate values (2, '19981002'); select CAST(C02 as DATE Format 'YYYYMMDD') from TestCastDate;
I suggest checking the actual data in the source column.