18 May 2018        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');

Read great educational content like this and a lot more ! Create my free account now 🎁