Genial!
Das hat mir noch gefehlt, jetzt funktioniert es:
Code:
CREATE OR ALTER procedure GET_ERFNR (
JAHR varchar(2) not null,
WOCHE varchar(2) not null)
returns (
ERFNR integer)
as
declare variable ANZ integer;
declare variable GEN_NAME varchar(10);
begin
/* Procedure Text */
gen_name = 'ERFNR' || Jahr || Woche;
SELECT COUNT(1) from rdb$generators where rdb$generator_name = :gen_name into :anz;
if (anz <> 1) then
execute statement 'create sequence ' || gen_name;
execute statement 'SELECT GEN_ID(' || gen_name || ', 1) from rdb$database' into :erfnr;
suspend;
end