18 May 2018 · npac ·       Add to Favorites   Report

Compare date column with varchar in Teradata


We need to retrieve the rows that service_date is greater than prod_date. 

  • The data type for prod_date is VARCHAR(10) (2/20/2014 for example) 
  • and the data type for service_date is DATE (YYYYMMDD)


So to keep things simple, it makes sense to cast PROD_DATE to a date when comparing these two fields like :

where S.SERVICE_DATE >= cast(P.PROD_DATE as date format 'DD/MM/YYYY');


posted on 18 May 2018

Read great educational content like this and a lot more !

Members get free exclusive access to content, new courses, and discounts. Signup for a free account to write a post / comment / upvote posts. Creating an account takes less than 5 seconds and you can start earning badges & points too