Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 09 Jan 2008 @ 16:17:17 GMT


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


Subj:   Re: Most efficient way to make Date field into char(4) YYMM
 
From:   Michael Larkins

Anomy.Anom:

It would certainly be possible to match on the YYMM portion of a date. However, you have ignored a simple truth in your:

     > >  where tbl1.date_YYMM = cast(current_date as char(4)) (format'YYMM')

Once you convert the date to a CHAR there is no longer anything to denote 'YYMM'. You have to format it while it is still a date:

     where tbl1.date_YYMM = current_date(format'YYMM');

Then, since your date_YYMM is probably a CHAR column than you need to add the CHAR attribute to it:

     where tbl1.date_YYMM = current_date(format'YYMM')(char(4));

You could also do:

     where tbl1.date_YYMM = cast((current_date(format'YYMM')) as (char(4));

Hope this helps.

Michael Larkins
Certified Teradata Master
Certified Teradata SQL Instructor



     
  <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