-- 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 foobar(id INTEGER, k INTEGER, v INTEGER, PRIMARY KEY(id))
GO

INSERT INTO foobar VALUES(1, 1, 2)
GO
INSERT INTO foobar VALUES(2, 1, 1)
GO
INSERT INTO foobar VALUES(3, 1, 4)
GO
INSERT INTO foobar VALUES(4, 1, 3)
GO
INSERT INTO foobar VALUES(5, 2, 0)
GO

SELECT * FROM foobar
GO

DECLARE c CURSOR SCROLL FOR SELECT * FROM foobar ORDER BY id
OPEN c
FETCH FIRST FROM c
FETCH LAST FROM c
CLOSE c
DEALLOCATE c
GO

DROP TABLE foobar
GO
