Author |
Message
|
sanupoju |
Posted: Fri Sep 13, 2013 2:23 am Post subject: How to count by using cardinality function |
|
|
Newbie
Joined: 31 Jul 2012 Posts: 3
|
Hello All,
For example, CARDINALITY(InputRoot.XMLNSC.root.sub[].child[])
In the above statement, we have multiple sub tags and child tags, but I wanted to count no. of child tags present in all sub tags without using any loopings.
please correct me to handle this situation.
Last edited by sanupoju on Fri Sep 13, 2013 2:37 am; edited 1 time in total |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Sep 13, 2013 2:29 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
No, you don't want to count these.
You want to solve the real requirement using some other method. |
|
Back to top |
|
 |
sanupoju |
Posted: Fri Sep 13, 2013 2:50 am Post subject: |
|
|
Newbie
Joined: 31 Jul 2012 Posts: 3
|
mqjeff wrote: |
No, you don't want to count these.
You want to solve the real requirement using some other method. |
Thanks for reply,
actually if the message is like below:
<custdetails>
<contactpoint>
<telinfo>..</telinfo>
<telinfo>..</telinfo>
</contactpoint>
<contactpoint>
<telinfo>..</telinfo>
</contactpoint>
<contactpoint>
<telinfo>..</telinfo>
<telinfo>..</telinfo>
</contactpoint>
</custdetails>
Pls note that xml structure was, custdetails-->contactpoint-->telinfo
How can we count the "telinfo" tag present in the above msg. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Sep 13, 2013 2:54 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Why do you want to count them? |
|
Back to top |
|
 |
smdavies99 |
Posted: Fri Sep 13, 2013 3:18 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
mqjeff wrote: |
Why do you want to count them? |
Because that's the requirement....
{ducks to avoid incoming <redacted>} _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Sep 13, 2013 4:55 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
smdavies99 wrote: |
mqjeff wrote: |
Why do you want to count them? |
Because that's the requirement....
{ducks to avoid incoming <redacted>} |
I'm holding up two fingers. It's a binary counting system, I assure you.
 |
|
Back to top |
|
 |
Vitor |
Posted: Fri Sep 13, 2013 5:33 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
sanupoju wrote: |
How can we count the "telinfo" tag present in the above msg. |
Why do you need to have a count of these elements?
What's wrong with looping?
And as indicated, don't say "because the requirement is to count these without looping". _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Sep 13, 2013 5:38 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Vitor wrote: |
And as indicated, don't say "because the requirement is to count these without looping". |
And don't say "I need to know how many there are so I can loop over the count". |
|
Back to top |
|
 |
Tibor |
Posted: Fri Sep 13, 2013 6:34 am Post subject: |
|
|
 Grand Master
Joined: 20 May 2001 Posts: 1033 Location: Hungary
|
You could try something like this:
Code: |
DECLARE iCnt INTEGER 0;
FOR src AS InputRoot.XMLNSC.custdetails.contactpoint[] DO
SET iCnt = iCnt + CARDINALITY(src.telinfo[]);
END FOR; |
(not tested.) |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Sep 13, 2013 6:54 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Tibor wrote: |
You could try something like this:
Code: |
DECLARE iCnt INTEGER 0;
FOR src AS InputRoot.XMLNSC.custdetails.contactpoint[] DO
SET iCnt = iCnt + CARDINALITY(src.telinfo[]);
END FOR; |
(not tested.) |
And yet, that uses a loop.
And yet, so does CARDINALITY, even if it's under the covers.
I can think of another way to do this in ESQL without using an explicit loop.
But it still shouldn't be done in almost all cases. |
|
Back to top |
|
 |
Tibor |
Posted: Fri Sep 13, 2013 7:10 am Post subject: |
|
|
 Grand Master
Joined: 20 May 2001 Posts: 1033 Location: Hungary
|
OK, I had not read the question carefully before I responded...  |
|
Back to top |
|
 |
|