Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / May 2008

Tip: Looking for answers? Try searching our database.

Knut's function "elelments"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lenygold - 02 May 2008 23:17 GMT
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?
Lennart - 03 May 2008 16:22 GMT
> Need help with Knut's function for  summing values in rows
> here is my example:
[quoted text clipped - 34 lines]
>  10 record(s) selected.
> why it is summing wrong?

For one thing, you can't do:

int(substr(all_sum, index-1,1))

because there are numbers with more than 1 digit.

/Lennart
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.