Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 11 of 11 total
Thread Convert Field Type & Calculate
Mon, Jul 21 2014 4:32 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ben


>At this point I realized duaration is entered as an integer so it does not
>cause any problems on conversion. I do have situations where its
>entered in time format (00:00) noting hours and minutes. The only way I was
>thinking was using the subString function. That would be fine if
>all parts (before and after the colon) were the same length. But since
>simplicity is an impossibility I might have to run thru it programatically
>converting every number to an integer or decimal - that is unless you have a
>better idea.

Sure have. ElevateDB has a couple of nice features. Whilst it was possible to add external functions to the engine in DBISAM in ElevateDB the architecture is such that the additions can be used in EDBManager as well as your apps. The other feature, and the one I advise using here, is that ElevateDB has its own programming language built in.

Here's your starter for 10

CREATE FUNCTION "DurationStringToInteger" (IN "DurationText" CHAR(30) COLLATE "ANSI_CI")
RETURNS INTEGER
BEGIN
DECLARE LBit VARCHAR;
DECLARE RBit VARCHAR;
DECLARE Result INTEGER;

SET LBit = TRIM(BOTH ' ' FROM DurationText);
                                  
BEGIN
IF 0 = POS(':',LBit) THEN
 SET Result = CAST(Lbit AS INTEGER);
ELSE
SET RBit = SUBSTR(LBit, POS(':',LBit)+1,30);
SET LBit = SUBSTR(LBit,1,POS(':',LBit)-1);
SET Result = (CAST(LBit AS INTEGER) * 60) + CAST(RBit AS INTEGER);
END IF;
EXCEPTION
SET Result = -1;
END;
  
RETURN Result;

END
VERSION 1.00!

In EDBManager navigate to your database, paste the above into a new sql window and run it - you will then have a function IN THAT DATABASE that can convert on the fly. The emphasis is because functions are on a database by database basis not on a session or engine basis.

Roy Lambert
« Previous PagePage 2 of 2
Jump to Page:  1 2
Image