Subject | Again SP Questions from a NewBie |
---|---|
Author | Burak OZLER |
Post date | 2001-11-19T08:43:16Z |
Hi All,
I have problems with the IB's trigger&SP language especially with IF
THEN BEGIN END ELSE BEGIN END statements. I don't understand why we don't
put semicolon after IF THEN ELSE Statements. And why I could not put any
statement after IF THEN BEGIN END ELSE BEGIN END, if I try I have errors. So
I need some "realy doin somethin" SP&Trigger examples, becouse the
employee.gdb only have 4, 3 of it about same sentence. May be I'm wrong
choosing FB for a project includes over 100 tables and over 150 SP's and
much more trigger.
This SP's aim to bring the value from another currency
The DOVKART Table DOVKOD Varchar (5) , NAME varchar (20)
USD, USDollar
DEM, Deutche Mark
TRL, Turkish Lira
The DOVKUR table TARIH date,DOVKOD varchar(5),ALISKUR numeric(17,2),SATISKUR
numeric (17,2)
18.11.2001 DEM 760000 765000
18.11.2001 USD 1550000 1560000
18.11.2001 TRL 1 1
I'm sending this values to KUR_DONUSTUR (18.11.2001,USD,DEM, 500,1 )
the result must be this
500 * (1560000/765000)
500 * 2,039215686274509803921568627451
1019,6078431372549019607843137255
the result must be 1019,60 but I get Null
how can I solve these problems????
CREATE PROCEDURE KUR_DONUSTUR (
TARIH DATE,
FROMKUR VARCHAR(5),
TOKUR VARCHAR(5),
TUTAR NUMERIC(17,2),
SATIS SMALLINT)
RETURNS (
KUR NUMERIC(17,2))
AS
declare variable FROMKURASMONEY NUMERIC (17,2);
declare variable TOKURASMONEY NUMERIC (17,2);
begin
/* SATIS = 1 İSE SATIŞ KURU 0 İSE ALIŞ KURU */
EXECUTE PROCEDURE getdovizkur :FROMKUR , :TARIH , :SATIS returning_values
:FROMKURASMONEY;
if (:FROMKURASMONEY <> 0) then
BEGIN
EXECUTE PROCEDURE getdovizkur :TOKUR , :TARIH , :SATIS returning_values
:TOKURASMONEY;
KUR = TUTAR * (:FROMKURASMONEY / :TOKURASMONEY);
END ELSE KUR = 0;
END
CREATE PROCEDURE GETDOVIZKUR (
DOVKOD VARCHAR(5),
TARIH DATE,
TIP SMALLINT)
RETURNS (
KUR NUMERIC(17,2))
AS
begin
if (TIP=0) then /* ALIŞ */
BEGIN
SELECT ALISKUR
FROM DOVKUR
WHERE DOVKOD = :DOVKOD AND TARIH = :TARIH
INTO :KUR;
if (KUR IS NULL) then
BEGIN
KUR = 0;
exception "doviz_girilmemis";
END
END ELSE /* SATIŞ */
BEGIN
SELECT SATISKUR
FROM DOVKUR
WHERE DOVKOD = :DOVKOD AND TARIH = :TARIH
INTO :KUR;
if (KUR IS NULL) then
BEGIN
KUR = 0;
exception "doviz_girilmemis";
END
END
suspend;
end
I have problems with the IB's trigger&SP language especially with IF
THEN BEGIN END ELSE BEGIN END statements. I don't understand why we don't
put semicolon after IF THEN ELSE Statements. And why I could not put any
statement after IF THEN BEGIN END ELSE BEGIN END, if I try I have errors. So
I need some "realy doin somethin" SP&Trigger examples, becouse the
employee.gdb only have 4, 3 of it about same sentence. May be I'm wrong
choosing FB for a project includes over 100 tables and over 150 SP's and
much more trigger.
This SP's aim to bring the value from another currency
The DOVKART Table DOVKOD Varchar (5) , NAME varchar (20)
USD, USDollar
DEM, Deutche Mark
TRL, Turkish Lira
The DOVKUR table TARIH date,DOVKOD varchar(5),ALISKUR numeric(17,2),SATISKUR
numeric (17,2)
18.11.2001 DEM 760000 765000
18.11.2001 USD 1550000 1560000
18.11.2001 TRL 1 1
I'm sending this values to KUR_DONUSTUR (18.11.2001,USD,DEM, 500,1 )
the result must be this
500 * (1560000/765000)
500 * 2,039215686274509803921568627451
1019,6078431372549019607843137255
the result must be 1019,60 but I get Null
how can I solve these problems????
CREATE PROCEDURE KUR_DONUSTUR (
TARIH DATE,
FROMKUR VARCHAR(5),
TOKUR VARCHAR(5),
TUTAR NUMERIC(17,2),
SATIS SMALLINT)
RETURNS (
KUR NUMERIC(17,2))
AS
declare variable FROMKURASMONEY NUMERIC (17,2);
declare variable TOKURASMONEY NUMERIC (17,2);
begin
/* SATIS = 1 İSE SATIŞ KURU 0 İSE ALIŞ KURU */
EXECUTE PROCEDURE getdovizkur :FROMKUR , :TARIH , :SATIS returning_values
:FROMKURASMONEY;
if (:FROMKURASMONEY <> 0) then
BEGIN
EXECUTE PROCEDURE getdovizkur :TOKUR , :TARIH , :SATIS returning_values
:TOKURASMONEY;
KUR = TUTAR * (:FROMKURASMONEY / :TOKURASMONEY);
END ELSE KUR = 0;
END
CREATE PROCEDURE GETDOVIZKUR (
DOVKOD VARCHAR(5),
TARIH DATE,
TIP SMALLINT)
RETURNS (
KUR NUMERIC(17,2))
AS
begin
if (TIP=0) then /* ALIŞ */
BEGIN
SELECT ALISKUR
FROM DOVKUR
WHERE DOVKOD = :DOVKOD AND TARIH = :TARIH
INTO :KUR;
if (KUR IS NULL) then
BEGIN
KUR = 0;
exception "doviz_girilmemis";
END
END ELSE /* SATIŞ */
BEGIN
SELECT SATISKUR
FROM DOVKUR
WHERE DOVKOD = :DOVKOD AND TARIH = :TARIH
INTO :KUR;
if (KUR IS NULL) then
BEGIN
KUR = 0;
exception "doviz_girilmemis";
END
END
suspend;
end