18 May 18 · npack · #teradata ·   Bookmark   ×

Compare date column with varchar in Teradata

Scenario:

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)


Solution:

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');


npack

posted on 18 May 18

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds

Copied