update table based on the lastest timestamp rec

Database
The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.
KN
Enthusiast

update table based on the lastest timestamp rec

Hi Gurus,

 

In a Stored Procedue that i created , using cursors i am processing some records and before each record is processed i make an entry into the log table.

                             Starttime                 col  col   col  Endtime  Status

insert into log ( current_timestamp(0), val, val ,val ,NULL , 'Begin' );

 

Once the processing is done i have to update the log table status from 'Begin' to 'END' based on the most recent record ie ( startime )

 

what would be the update syntax for it?

 

thanks

KN

 

2 REPLIES 2
Teradata Employee

Re: update table based on the lastest timestamp rec

Since you are already using a cursor, just keep the start time as a local variable.

 

DECLARE theStart TIMESTAMP(0);
…
-- For each iteration 
SET theStart = CURRENT_TIMESTAMP(0);
INSERT INTO LOG (:theStart, val1, val2, val3, NULL, 'Begin');
-- Do more processing
UPDATE LOG
  SET Endtime=CURRENT_TIMESTAMP(0) , Status='END'
  WHERE Starttime=:theStart;
KN
Enthusiast

Re: update table based on the lastest timestamp rec

Thanks Fred. Thats a smart solution and simple one than the update.

I shall incorporate by holding it in a local variable.

 

 

Thanks

KN