Sunteți pe pagina 1din 2

Teradata Timestamp tips & tric s Some tips which might be useful while wor ing on date and

timestamp. (queries ru n andverified on V2R6) Tip 1: Create Timestamp from Date and TimeSELECT CAST ( CAST (CURRENT_DATE AS FORMAT 'YYYY-MM-DD') ||' '|| CAST ( CAST (CURRENT_TIME AS FOR MAT'HH:MI:SS') AS CHAR(8)) AS TIMESTAMP(0)); SELECT CAST (CURRENT_DATE AS TIMESTAMP(0)) + ((CURRENT_TIME- TIME '00:00:00')HOUR TO SECOND(0)); Tip 2: Convert timestamp field in Teradata into format 'MMM-YYYY'select CURRENT_TIMESTAMP(FORMAT 'MMM-YYYY'); Current TimeStamp(6)-------------------Ma r-2010 Tip 3: Inserting current_timestamp value into timestamp(0) columnCreate table stats (record_time TIMESTAMP(0)); Whenever we try to populate the current_timestamp v alue into this column usinginsert into stats(record_time) select current_timesta mp ; we get following error.7454: Date Time field overflow. To avoid this, we ha ve two solutionsSolutions:1. Data type for CURRENT_TIMESTAMP is TIMESTAMP(6) and you are trying to insert a TIMESTAMP(6) data to a TIMESTAMP(0) and that's why y ou are getting this error.insert into stats(record_time) Sel cast (CURRENT_DATE as TimeStamp(0)) +((CURRENT_TIME-time '00:00:00')hour to second(0)) ; 2. insert into stats

(record_time) select CURRENT_TIMESTAMP(0); Tip 4: Add minutes to timestamp How to add 10 minutes to current timestamp in TD? SEL CURRENT_TIMESTAMP+INTERVAL '10' MINUTE. The following example is ta en straigh t from Teradata Functions and Operators referencemanual.Example 1: Subtract two TIMESTAMP TypesConsider the following table: CREATE TABLE BillDateTime(start_time TIMESTAMP(0),end_time TIMESTAMP(0)); Determine the di fference, specifying an Interval unit of DAY TO SECOND for the result:

S-ar putea să vă placă și