Archives of the TeradataForum
Message Posted: Thu, 23 Aug 2012 @ 09:36:18 GMT
Subj: | | Re: How to replace with null if date is invalid |
|
From: | | Carlos Carpio Garcia |
As I understand, the input field must be a character , since '2012-30-30' is not allowed in a date field.
What I would do is selecting a subset of SYS_CALENDAR.CALENDAR and typecasting the date to CHAR in order to do the comparisons.
If your table was called TEST_TABLE with a character(10) TEST_DATE field, I'd do something like this.
Select
TEST_DATE,
calendar_date
From
TEST_TABLE Left Join
(
Select
calendar_date (Date, Format 'yyyy-mm-dd') (Char(10)) txt_date,
calendar_date
From
SYS_CALENDAR.CALENDAR
Where
calendar_date Between '1950-01-01' And Add_Months(Date,5*12)
) On
TEST_DATE=txt_date
;
Carlos Carpio Garcia
"la Caixa" Servicios Centrales / Tecnolog?a
|