I realise that I could use two nested for loops one going forward to get each number and one going backward to make sure the number hasn't previously existed but I was wondering if there was a cleaner way possibly by using a SELECT statement.
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
Using for loops the code would look like the following
DECLARE FWD INTEGER 2; --forward counter
DECLARE REV INTEGER; --reverse counter
DECLARE TOP INTEGER; --number of items
DECLARE X INTEGER 2; --output counter
DECLARE FLAG CHARACTER ''; --Equal flag
SET TOP=CARDINALITY(InputRoot.XML.Root.Code[]); -- number of items
SET OutputRoot.XML.Root.Code[1] = InputRoot.XML.Root.Code[1]; -- the first number is always unique
WHILE FWD <= TOP DO
SET REV = FWD - 1;
WHILE REV > 0 DO
IF InputRoot.XML.Root.Code[FWD] =
InputRoot.XML.Root.Code[REV] THEN
SET FLAG = 'EQUAL'; -- current code compared to all previous codes 4 <> 1,2 or 3
END IF;
SET REV = REV - 1;
END WHILE;
-- If there were no matching previous codes
IF FLAG <> 'EQUAL' THEN
SET OutputRoot.XML.Root.Code[X] =
InputRoot.XML.Root.Code[FWD];
SET X = X + 1;
END IF;
SET FLAG = '';
SET FWD = FWD + 1;
END WHILE;
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum