Subject | Re: [ib-support] Re: If statements in an SP |
---|---|
Author | R. Tulloch |
Post date | 2002-07-31T18:45:23Z |
What is the difference?
SET TERM ## ;
CREATE PROCEDURE GetNextInfoId
RETURNS (gotid INTEGER)
AS
DECLARE VARIABLE currentid INTEGER;
DECLARE VARIABLE nextid INTEGER;
DECLARE VARIABLE startflag INTEGER;
BEGIN
startflag = 0;
FOR SELECT ID
FROM INFOLIST
WHERE ID >= 1 AND ID <= 4999
ORDER BY ID ASC
INTO nextid
DO
BEGIN
IF ((nextid > 1) AND (startflag = 0)) THEN
BEGIN
gotid = nextid-1;
EXECUTE PROCEDURE InsertNewInfo (gotid);
SUSPEND;
EXIT;
END
ELSE IF ((nextid IS NULL) AND (startflag = 0)) THEN
BEGIN
gotid = 1;
EXECUTE PROCEDURE InsertNewInfo (gotid);
SUSPEND;
EXIT;
END
ELSE
BEGIN
IF (startflag = 0) THEN
BEGIN
currentid = nextid;
startflag = 1;
END
IF (nextid = 4999) THEN
BEGIN
gotid = -1;
SUSPEND;
EXIT;
END
ELSE IF (nextid > currentid + 1) THEN
BEGIN
gotid = currentid + 1;
EXECUTE PROCEDURE InsertNewInfo (gotid);
SUSPEND;
EXIT;
END
ELSE IF (nextid = currentid + 1) THEN
currentid = currentid + 1;
END
END
BEGIN
gotid = currentid + 1;
EXECUTE PROCEDURE InsertNewInfo (gotid);
SUSPEND;
EXIT;
END
END ##
SET TERM ; ##
SET TERM ## ;
CREATE PROCEDURE GetNextInfoId
RETURNS (gotid INTEGER)
AS
DECLARE VARIABLE currentid INTEGER;
DECLARE VARIABLE nextid INTEGER;
DECLARE VARIABLE startflag INTEGER;
BEGIN
startflag = 0;
FOR SELECT ID
FROM INFOLIST
WHERE ID >= 1 AND ID <= 4999
ORDER BY ID ASC
INTO nextid
DO
BEGIN
IF ((nextid > 1) AND (startflag = 0)) THEN
BEGIN
gotid = nextid-1;
EXECUTE PROCEDURE InsertNewInfo (gotid);
SUSPEND;
EXIT;
END
ELSE IF ((nextid IS NULL) AND (startflag = 0)) THEN
BEGIN
gotid = 1;
EXECUTE PROCEDURE InsertNewInfo (gotid);
SUSPEND;
EXIT;
END
ELSE
BEGIN
IF (startflag = 0) THEN
BEGIN
currentid = nextid;
startflag = 1;
END
IF (nextid = 4999) THEN
BEGIN
gotid = -1;
SUSPEND;
EXIT;
END
ELSE IF (nextid > currentid + 1) THEN
BEGIN
gotid = currentid + 1;
EXECUTE PROCEDURE InsertNewInfo (gotid);
SUSPEND;
EXIT;
END
ELSE IF (nextid = currentid + 1) THEN
currentid = currentid + 1;
END
END
BEGIN
gotid = currentid + 1;
EXECUTE PROCEDURE InsertNewInfo (gotid);
SUSPEND;
EXIT;
END
END ##
SET TERM ; ##