taT4Sql | Comparing different Date formats using Teradata SQL

In a recent post, I shared code on how to change timestamp format from one style to another. Today, we do similar tweaks for date formats, as I had to do comparison between dates having different formats, on either side of operand in WHERE clause.

Trick 2 Compare Diff Formats..

Suppose, your table has a column having format ‘YYYY-MM-DD’ and you have to do comparison with a column having this format ‘YYYYMMDD’.

SEL *
FROM SOME_TBL
WHERE
CAST( CAST( YYYY_MM_DD_CLMN AS CHAR(10)) AS INTEGER) = YYYYMMDD_CLMN

Hope this helps..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s