Subject | Stored Procedure Question |
---|---|
Author | enseagui |
Post date | 2007-01-30T21:26:06Z |
Here is a stored procedure that is not working as I would like.
This SP is supposed to update the record with a TickTime one minute
before. But actually it will not update.
CREATE PROCEDURE CALCSPEED (
SYMB Varchar(10) )
AS
DECLARE VARIABLE Price0 DOUBLE PRECISION;
DECLARE VARIABLE Price1 DOUBLE PRECISION;
DECLARE VARIABLE Price2 DOUBLE PRECISION;
DECLARE VARIABLE S DOUBLE PRECISION;
DECLARE VARIABLE ONEMIN DOUBLE PRECISION;
DECLARE VARIABLE TTime TIMESTAMP;
BEGIN
ONEMIN = CAST(1 as DOUBLE PRECISION)/CAST(24 as DOUBLE
PRECISION)/CAST(60 as DOUBLE PRECISION);
FOR SELECT Close,TickTime FROM MINUTEDATA Where Symbol=:Symb Order
by TickTime
INTO :Price2,:TTime
DO
BEGIN
IF (Price0 IS NOT NULL) THEN
BEGIN
S = Price2-Price0;
UPDATE MINUTEDATA Set Speed=:S where
TickTime=:TTime-:ONEMIN and Symbol=:Symb;
END
Price0 = Price1;
Price1 = Price2;
END
END^
This is how I solved the problem but still I would like to understand
why the first version would not work. I am using FB embedded 1.5
CREATE PROCEDURE CALCSPEED (
SYMB Varchar(10) )
AS
DECLARE VARIABLE Price0 DOUBLE PRECISION;
DECLARE VARIABLE Price1 DOUBLE PRECISION;
DECLARE VARIABLE Price2 DOUBLE PRECISION;
DECLARE VARIABLE S DOUBLE PRECISION;
DECLARE VARIABLE ONEMIN DOUBLE PRECISION;
DECLARE VARIABLE TTime TIMESTAMP;
DECLARE VARIABLE TTime0 TIMESTAMP;
BEGIN
ONEMIN = CAST(1 as DOUBLE PRECISION)/CAST(24 as DOUBLE
PRECISION)/CAST(60 as DOUBLE PRECISION);
FOR SELECT Close,TickTime FROM MINUTEDATA Where Symbol=:Symb Order
by TickTime
INTO :Price2,:TTime
DO
BEGIN
IF (Price0 IS NOT NULL) THEN
BEGIN
S = Price2-Price0;
UPDATE MINUTEDATA Set Speed=:S where TickTime=:TTime0 and
Symbol=:Symb;
END
Price0 = Price1;
Price1 = Price2;
TTime0 = TTime;
END
END^
This SP is supposed to update the record with a TickTime one minute
before. But actually it will not update.
CREATE PROCEDURE CALCSPEED (
SYMB Varchar(10) )
AS
DECLARE VARIABLE Price0 DOUBLE PRECISION;
DECLARE VARIABLE Price1 DOUBLE PRECISION;
DECLARE VARIABLE Price2 DOUBLE PRECISION;
DECLARE VARIABLE S DOUBLE PRECISION;
DECLARE VARIABLE ONEMIN DOUBLE PRECISION;
DECLARE VARIABLE TTime TIMESTAMP;
BEGIN
ONEMIN = CAST(1 as DOUBLE PRECISION)/CAST(24 as DOUBLE
PRECISION)/CAST(60 as DOUBLE PRECISION);
FOR SELECT Close,TickTime FROM MINUTEDATA Where Symbol=:Symb Order
by TickTime
INTO :Price2,:TTime
DO
BEGIN
IF (Price0 IS NOT NULL) THEN
BEGIN
S = Price2-Price0;
UPDATE MINUTEDATA Set Speed=:S where
TickTime=:TTime-:ONEMIN and Symbol=:Symb;
END
Price0 = Price1;
Price1 = Price2;
END
END^
This is how I solved the problem but still I would like to understand
why the first version would not work. I am using FB embedded 1.5
CREATE PROCEDURE CALCSPEED (
SYMB Varchar(10) )
AS
DECLARE VARIABLE Price0 DOUBLE PRECISION;
DECLARE VARIABLE Price1 DOUBLE PRECISION;
DECLARE VARIABLE Price2 DOUBLE PRECISION;
DECLARE VARIABLE S DOUBLE PRECISION;
DECLARE VARIABLE ONEMIN DOUBLE PRECISION;
DECLARE VARIABLE TTime TIMESTAMP;
DECLARE VARIABLE TTime0 TIMESTAMP;
BEGIN
ONEMIN = CAST(1 as DOUBLE PRECISION)/CAST(24 as DOUBLE
PRECISION)/CAST(60 as DOUBLE PRECISION);
FOR SELECT Close,TickTime FROM MINUTEDATA Where Symbol=:Symb Order
by TickTime
INTO :Price2,:TTime
DO
BEGIN
IF (Price0 IS NOT NULL) THEN
BEGIN
S = Price2-Price0;
UPDATE MINUTEDATA Set Speed=:S where TickTime=:TTime0 and
Symbol=:Symb;
END
Price0 = Price1;
Price1 = Price2;
TTime0 = TTime;
END
END^