Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 13 Jul 2007 @ 08:20:46 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: varhar(8) to date
 
From:   Nimmala, Meher Tej

Hi Vivek,

Use case statement as shown below

     , CASE ERDAT
     WHEN '00/00/0000' THEN CAST('9999-12-31' AS DATE FORMAT 'YYYY-MM-DD')
     WHEN '00-00-0000' THEN CAST('9999-12-31' AS DATE FORMAT 'YYYY-MM-DD')
     WHEN '00000000' THEN CAST('9999-12-31' AS DATE FORMAT 'YYYY-MM-DD')
     WHEN '0000/00/00' THEN CAST('9999-12-31' AS DATE FORMAT 'YYYY-MM-DD')
     WHEN '0000-00-00' THEN CAST('9999-12-31' AS DATE FORMAT 'YYYY-MM-DD')
     WHEN '12/31/9999' THEN CAST(ERDAT AS DATE FORMAT 'MM/DD/YYYY')
     WHEN '12-31-9999' THEN CAST(ERDAT AS DATE FORMAT 'MM-DD-YYYY')
     WHEN '12319999' THEN CAST(ERDAT AS DATE FORMAT 'MMDDYYYY')
     WHEN '99991231' THEN CAST(ERDAT AS DATE FORMAT 'YYYYMMDD')
     WHEN '9999/12/31' THEN CAST(ERDAT AS DATE FORMAT 'YYYY/MM/DD')
     WHEN '9999-12-31' THEN CAST(ERDAT AS DATE FORMAT 'YYYY-MM-DD')
     ELSE
     CASE SUBSTR(ERDAT,3,1)
     WHEN '/' THEN CAST(ERDAT AS DATE FORMAT 'MM/DD/YYYY')
     WHEN '-' THEN CAST(ERDAT AS DATE FORMAT 'MM-DD-YYYY')
     ELSE
     CASE CHARACTER_LENGTH(TRIM(ERDAT))
     WHEN 10 THEN CAST(ERDAT AS DATE FORMAT 'YYYY-MM-DD')
     WHEN 8 THEN CAST(ERDAT AS DATE FORMAT 'YYYYMMDD')
     ELSE CAST((TRIM(ERDAT )) AS DATE FORMAT 'YYYYMMDD')
     END
     END
     END ERDAT

This should resolve ur problem.


Thanks

Meher Tej Nimmala



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023