ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Sorting for Unique with ESQL

Post new topic  Reply to topic
 Sorting for Unique with ESQL « View previous topic :: View next topic » 
Author Message
EnOne
PostPosted: Fri May 21, 2004 8:27 am    Post subject: Sorting for Unique with ESQL Reply with quote

Centurion

Joined: 09 Oct 2002
Posts: 100
Location: Kansas City

I have a list like this

<Root>
<Code>001</Code>
<Code>001</Code>
<Code>122</Code>
<Code>022</Code>
<Code>021</Code>
<Code>001</Code>
<Code>001</Code>
<Code>001</Code>
<Code>022</Code>
<Code>122</Code>
<Code>001</Code>
<Code>111</Code>
<Code>001</Code>
<Code>001</Code>
<Code>001</Code>
<Code>001</Code>
</Root>

And I'm trying to get a list of the unique numbers like this

<Root>
<Code>001</Code>
<Code>122</Code>
<Code>022</Code>
<Code>021</Code>
<Code>111</Code>
</Root>

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.
Back to top
View user's profile Send private message
EnOne
PostPosted: Fri May 21, 2004 9:33 am    Post subject: Reply with quote

Centurion

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;
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Sorting for Unique with ESQL
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.