Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread How to cast a variable to timestamp
Fri, Jun 3 2011 5:18 AMPermanent Link

durumdara

Hi!

I search for a way to cast a procedure variable to time to add to another time variable.

For example:

set oldtime = current_timestamp;
set min = ........
....
set timediff = cast (min as minute);
set newtime = oldtime + timediff;

How can I do it?

I try with everything, for example:
cast('00:' + cast(perc as varchar(2)) + ':00);

But I don't found a solution to avoid "constant needed" error.

Thanks:
  dd
Fri, Jun 3 2011 5:38 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Welcome to the wonderful world of INTERVAL.


The syntax is totally different from DBISAM. You'll now need to do something like

UPDATE table SET  oldtime = oldtime +CAST( min as interval minute)


Roy Lambert [Team Elevate]
Fri, Jun 3 2011 12:26 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com



<< I search for a way to cast a procedure variable to time to add to another
time variable. >>

Use something like this:

SCRIPT
BEGIN
  DECLARE OldTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP();
  DECLARE MinDiff INTERVAL MINUTE DEFAULT INTERVAL '10' MINUTE;
  DECLARE NewTime TIMESTAMP;

  SET NewTime = OldTime + MinDiff;
  SET LOG MESSAGE TO 'Old Time: '+CAST(OldTime AS VARCHAR)+' '+
                     'New Time: '+CAST(NewTime AS VARCHAR);
END

In general, don't use keywords like 'Min' for variable names, you'll get
parsing errors because the parser will think that you're trying to use the
MIN() aggregate function.

--
Tim Young
Elevate Software
www.elevatesoft.com
Fri, Jun 3 2011 1:55 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim


Well caught. I was reading it as an UPDATE statement but revisiting the OP it is a procedure. he's looking for.


Roy Lambert
Image