Subject | Re: [firebird-support] I'm really new to storedProc and need a little help |
---|---|
Author | Milan Babuskov |
Post date | 2003-08-25T18:59:04Z |
Just to add a few things:
Lucas Franzen wrote:
so you don't need FOR SELECT ... DO ...
Just do:
SELECT LU_RATE FROM LUTABLE WHERE LU_FIELD='PYNUM' INTO :hightn
So here's my idea of it:
SET TERM !!
CREATE PROCEDURE GETPAYNUM RETURNS (hightn INTEGER) AS
BEGIN
SELECT LU_RATE FROM LUTABLE WHERE LU_FIELD='PYNUM' INTO :hightn;
IF (LU_RATE IS NULL) THEN
BEGIN
INSERT INTO LUTABLE (LU_DESC,LU_FIELD,LU_RATE,LU_ORDER,LU_DEF)
VALUES ('PayNumber', 'PYNUM', 1, 0, 'N');
LU_RATE = 1;
END
ELSE
BEGIN
UPDATE LUTABLE SET LU_RATE=LU_RATE +1 WHERE LU_FIELD='PYNUM';
LU_RATE = LU_RATE + 1;
END
SUSPEND;
END!!
SET TERM ;
--
Milan Babuskov
http://fbexport.sourceforge.net
Lucas Franzen wrote:
>> CREATE PROCEDURE GETPAYNUM RETURNS (hightn INTEGER) ASThis looks like you're be getting only one single row from this select,
>> BEGIN
>> UPDATE LUTABLE SET LU_RATE=LU_RATE +1 WHERE LU_FIELD='PYNUM';
>> FOR SELECT LU_RATE FROM LUTABLE WHERE LU_FIELD='PYNUM' INTO hightn
so you don't need FOR SELECT ... DO ...
Just do:
SELECT LU_RATE FROM LUTABLE WHERE LU_FIELD='PYNUM' INTO :hightn
>> IF (LU_RATE IS NULL) THENThis second select is extra. You already know what value is there.
>> BEGIN
>> INSERT INTO LUTABLE (LU_DESC, LU_FIELD, LU_RATE, LU_ORDER,
>> LU_DEF)
>> VALUES ('PayNumber', 'PYNUM', 1, 0, 'N');
>>
>> SELECT LU_RATE FROM LUTABLE WHERE LU_FIELD='PYNUM' INTO
>> hightn;
So here's my idea of it:
SET TERM !!
CREATE PROCEDURE GETPAYNUM RETURNS (hightn INTEGER) AS
BEGIN
SELECT LU_RATE FROM LUTABLE WHERE LU_FIELD='PYNUM' INTO :hightn;
IF (LU_RATE IS NULL) THEN
BEGIN
INSERT INTO LUTABLE (LU_DESC,LU_FIELD,LU_RATE,LU_ORDER,LU_DEF)
VALUES ('PayNumber', 'PYNUM', 1, 0, 'N');
LU_RATE = 1;
END
ELSE
BEGIN
UPDATE LUTABLE SET LU_RATE=LU_RATE +1 WHERE LU_FIELD='PYNUM';
LU_RATE = LU_RATE + 1;
END
SUSPEND;
END!!
SET TERM ;
--
Milan Babuskov
http://fbexport.sourceforge.net