Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Saturday 29 August 2015

Convert TIMESTAMP in DATE data type format in TERADATA

Many times we need to compare two column and we succeed most of the time since we do have same data type and same values. But when it comes to different data types then it can be more difficult especially with date data type. When we need to compare date data type with timestamp data type. We can only compare this only when we convert the timestamp values in date data type. We can convert TIMESTAMP data type in DATE data type by using CAST in TERADATA.

Below is the example:-

Your Timestamp values is :- '2015-01-01 12:00:00'

dt_update   ----having date data type from EMP table.
updated_date_time ------having timestamp data type from EMPLOYEE table.

SELECT A.DT_UPDATE,CAST(B.UPDATED_DATE AS DATE FORMAT 'YYYY-MM-DD') AS UPDATED_DATE FROM EMP A,EMPLOYEE B
WHERE A.DT_UPDATE=B.UPDATED_DATE;

OR

SELECT A.DT_UPDATE,CAST(B.UPDATED_DATE AS DATE FORMAT 'YYYY-MM-DD') AS UPDATED_DATE FROM EMP A,EMPLOYEE B
WHERE A.DT_UPDATE=CAST(B.UPDATED_DATE AS DATE FORMAT 'YYYY-MM-DD');


No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.