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 » Help with SELECT

Post new topic  Reply to topic
 Help with SELECT « View previous topic :: View next topic » 
Author Message
aks
PostPosted: Mon Aug 16, 2004 4:52 pm    Post subject: Help with SELECT Reply with quote

Voyager

Joined: 19 Jul 2002
Posts: 84

I have xml that looks like this

<Field1>
<Value>1000</Value>
</Field1>
<Field2>
<Value>2000</Value>
</Field2>
<Field3>
<Value>3000</Value>
</Field3>
and so on etc

There can be many of these blocks (all optional though) and all begin with "Field" then an integer.

I want to sum all the Value elements with a select statement.
Not sure what to put in the FROM clause, or would I have to use a reference instead of a SELECT?
Thanks
Alan
Back to top
View user's profile Send private message
Nizam
PostPosted: Mon Aug 16, 2004 6:26 pm    Post subject: Reply with quote

Disciple

Joined: 10 Feb 2004
Posts: 160

aks,
I have never used select myself to do something what you r doing. But I want to give it a try.

Width = 1;
sum = 0;
path = InputRoot.XML.TOP_FILED.*[Width];
while(Lastmove)
do
if(substring(path from 1 to 5) = 'field') then
sum = sum + path.value
end if;
move Path NextSibling;
end while;

This is just an idea...
Let me know if this solves your purpose.....
Back to top
View user's profile Send private message
Missam
PostPosted: Mon Aug 16, 2004 7:16 pm    Post subject: Reply with quote

Chevalier

Joined: 16 Oct 2003
Posts: 424

Quote:
There can be many of these blocks (all optional though) and all begin with "Field" then an integer


what do you mean by all optional here .is your requirement can be some thing like this



Quote:
<Field1>
<Value>1000</Value>
</Field1>
<Field3>
<Value>2000</Value>
</Field3>
<Field6>
<Value>3000</Value>
</Field6>

with optional filed2 ,4 and 5
Back to top
View user's profile Send private message
aks
PostPosted: Mon Aug 16, 2004 9:19 pm    Post subject: Reply with quote

Voyager

Joined: 19 Jul 2002
Posts: 84

Sorry - optional means that the numbers will still be sequential, ie if there are 3 present, it wil have Field1, Field2 and Field3, but there can be anywhere from 0 onwards

Alan
Back to top
View user's profile Send private message
TDS_tds_tds
PostPosted: Thu Aug 19, 2004 12:19 pm    Post subject: SOLVED Reply with quote

Novice

Joined: 31 Jul 2003
Posts: 16

hey AKS, I have the solution for u.
but the xml on ur 1st post does not have a root element.... which makes it invalid xml data and mqsi will not parse it. ( i assume you forgot to post the root element). i just want to make sure you are aware of it.

so i added a root element "Test" to your xml .... here it is
Quote:
<Test><Field1><Value>1000</Value></Field1><Field2><Value>2000</Value></Field2><Field3><Value>3000</Value></Field3></Test>


And the code to calculate the sum is :
Code:
SET whatever = (SELECT SUM(CAST(myRef."Value" AS INTEGER)) FROM InputRoot.XML.Test.*[] AS myRef);


OR

Code:
SET whatever = (SELECT SUM(CAST(myRef.*[LAST] AS INTEGER)) FROM InputRoot.XML.Test.*[] AS myRef);


('whatever' in the above code refers to any variable or output tree element value or anything u want )


let me know if everything works cool for u.
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 » Help with SELECT
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.