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