Subject | Re: [firebird-support] SP Dialect independant |
---|---|
Author | Ivan Prenosil |
Post date | 2005-02-16T18:24:32Z |
CREATE OR ALTER PROCEDURE P (VAL INTEGER) RETURNS (RET INTEGER) AS
DECLARE VARIABLE HHMM VARCHAR(5);
BEGIN
HHMM = VAL;
WHILE (HHMM NOT LIKE '____%') DO HHMM = '0' || HHMM;
RET = 60 * CAST(SUBSTRING(HHMM FROM 1 FOR 2) AS INTEGER)
+ CAST(SUBSTRING(HHMM FROM 3 FOR 2) AS INTEGER);
END
Ivan
http://www.volny.cz/iprenosil/interbase/
DECLARE VARIABLE HHMM VARCHAR(5);
BEGIN
HHMM = VAL;
WHILE (HHMM NOT LIKE '____%') DO HHMM = '0' || HHMM;
RET = 60 * CAST(SUBSTRING(HHMM FROM 1 FOR 2) AS INTEGER)
+ CAST(SUBSTRING(HHMM FROM 3 FOR 2) AS INTEGER);
END
Ivan
http://www.volny.cz/iprenosil/interbase/
----- Original Message -----
From: "Nick Upson" <nick@...>
To: <firebird-support@yahoogroups.com>
Sent: Wednesday, February 16, 2005 5:32 PM
Subject: [firebird-support] SP Dialect independant
>
> I want to change this SP so as to get the same answer in dialect 1 or 3.
> (I'm having trouble getting the different arithmatic rules straight)
>
> CREATE PROCEDURE CONVTOMINS (PARAM1 INTEGER)
> returns (RESULT INTEGER)
> AS
> declare variable h Integer;
> declare variable m Integer;
> begin
> /* convert a time, held in an int as HHMM, into minutes since midnight */
>
> if (param1 is null or param1 = 0) then
> result = 0.00;
> else
> begin
> h = (param1 - 50) / 100; /* the '- 50' causes an effective chop, not
> round */
> m = param1 - (h * 100);
> result = (h * 60) + m;
> end
> end
> --
> Nick
> -----We Solve your Computer Problems---
> Founder & Listowner of the Prolifics User Group
> Panther, Ingres, UNIX, Interbase, Firebird - Available Shortly