-- Collection of code snippets by Arne Vajhøj 
-- (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
CREATE TABLE spdemo (
    id INTEGER NOT NULL,
    s VARCHAR(50),
    PRIMARY KEY(id)
);

INSERT INTO spdemo VALUES(1,'A');

DELIMITER //
CREATE PROCEDURE xinsert(_s varchar(50))
BEGIN
    DECLARE _maxid INTEGER;
    DECLARE _newid INTEGER;
    SELECT MAX(id) INTO _maxid FROM spdemo;
    SET _newid = _maxid + 3;
    INSERT INTO spdemo VALUES(_newid,_s);
END//
DELIMITER ;

CALL xinsert('BB');
CALL xinsert('CCC');

SELECT * FROM spdemo;

DROP PROCEDURE xinsert;
DROP TABLE spdemo;
