Subject Re: [firebird-support] Strange SP behaviour
Author Nando Dessena
Johannes,

J> ALTER PROCEDURE CREATE_C_ENTRY (VA_ID VARCHAR(10))
J> RETURNS (RC_ID INTEGER,
J> RA_ID VARCHAR(10),
J> RE_CODE VARCHAR(10))
J> AS

J> declare variable vE_CODE varchar(10);
J> declare variable vC_ID integer;
J> BEGIN
J> for select e_code from table_a where id = :vA_ID into :vE_CODE do begin

vC_ID = null;

J> select c_id from table_c where a_id = :vA_ID and e_code = :vE_CODE into :vC_ID;

J> if (vC_ID is null) then begin
J> vC_ID = gen_id(gen_een,1);
J> insert into table_c(c_id,a_id,e_code) values (:vC_ID,:vA_ID,:vE_CODE);
J> end else begin
J> update table_c set
J> c_id = :vC_ID,a_id = :vA_ID,e_code=:vE_CODE
J> where c_id = :vC_ID;
J> end
J> rC_ID = :vC_ID;
J> rE_CODE = :vE_CODE;
J> rA_ID = :vA_ID;
J> suspend;
J> end
J> END
J> ^
J> SET TERM ; ^
J> COMMIT WORK ;
J> SET AUTODDL ON;
J> SET TERM ^ ;

Ciao
--
Nando Dessena
======================================================
I support Firebird, I am a Firebird Foundation member!
Join today at http://www.firebirdsql.org/ff/foundation
======================================================