Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > IBM DB2 > Knut's function...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 8850 of 9056
Post > Topic >>

Knut's function "elelments"

by "lenygold via DBMonster.com" <u41482@[EMAIL PROTECTED] > May 2, 2008 at 10:17 PM

Need help with Knut's function for  summing values in rows 
here is my example:
WITH T1 (C1) AS
(VALUES ('1'),
       ('1.1'),
       ('1.2.1.2'),
       ('1.10.1'),
       ('1.10.1.2.2'),
       ('1.22.99.1'),
       ('1.2'),
       ('1.3.3.7.4'),  
       ('1.3.2.7'),
       ('1.4.1')),
T2(ALL_SUM) AS 
 (SELECT REPLACE(C1,'.','+') FROM T1)
select all_sum, sum(int(substr(all_sum, index-1,1))) FROM T2,
TABLE (elements(RTRIM(T2.all_sum)|| '+')) x 
where ordinal > 0 
group by all_sum
ORDER BY 1;

output:

ALL_SUM        2          
----------        -----------
1                      1
1+1                  2
1+10+1             2
1+10+1+2+2     6
1+2                  3
1+2+1+2           6
1+22+99+1      13
1+3+2+7          13
1+3+3+7+4      18
1+4+1               6

 10 record(s) selected.
why it is summing wrong?

-- 
Message posted via http://www.dbmonster.com
 




 2 Posts in Topic:
Knut's function "elelments"
"lenygold via DBMons  2008-05-02 22:17:14 
Re: Knut's function "elelments"
Lennart <Erik.Lennart.  2008-05-03 08:22:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Sun Jul 6 19:48:12 CDT 2008.