× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Tue, Jul 28, 2020 at 3:17 AM Maria Lucia Stoppa <mlstoppa@xxxxxxxxx>
wrote:

Everything works fine, except the same static SQL statement is run at least
twice to know the total number of rows (a simple count(*)) and the rows
themselves page by page.


GET DIAGNOSTIC DB2_NUMBER_ROWS is what you want to look at here.

If the previous SQL statement was an OPEN or a FETCH which caused the
size of the result table to be known, returns the number of rows in the
result
table. For SENSITIVE cursors, this value can be thought of as an
approximation since rows inserted and deleted will affect the next
retrieval of
this value. Otherwise, the value zero is returned.


Run it after you OPEN your cursor, before you FETCH.


Now, on the same data retrieved by this SQL statement, others select
statements must be run to get some totals according to different group by
clauses in order to present the data set distribution to the final user.


Have you looked at the OLAP functions in addition to ROLLUP, CUBE and
grouping sets?
https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/db2/rbafzolapexp.htm

https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/db2/rbafzgroupbyclause.htm


When I started writing SQL on the AS/400, (sub)totaling required an extra
statement.
That is no longer the case.

Charles

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.