Page 1 of 1

Count of rows returned by a cursor

PostPosted: Wed Mar 10, 2010 9:51 pm
by ctrevino
I am coding a cursor to sum up the data in a number of rows. I need to report a percentage that will be:
100 * sum/number of rows

What is the best way to get a count of the number of rows without doing a separate select? Can I include the count in my cursor declaration? Is this data included somewhere in the SQLCA?

Thanks,

Re: Count of rows returned by a cursor

PostPosted: Wed Mar 10, 2010 10:47 pm
by ctrevino
nevermind

Re: Count of rows returned by a cursor

PostPosted: Thu Mar 11, 2010 1:01 am
by dick scherrer
Hi Christy,

You're too quick for us :)

What did you decide to use?

Re: Count of rows returned by a cursor

PostPosted: Thu Mar 11, 2010 12:22 pm
by avik1983
Christy,
Please let us know what the best usage considering optimum performance u achived.Because usage of COUNT(*) will be pathetic for large number of rows :roll: :roll:

Re: Count of rows returned by a cursor

PostPosted: Thu Mar 11, 2010 9:29 pm
by ctrevino
well, my manager decided not to rewrite the IMS to a DB2 program (we are propagating some data and in this case I was going to use the propagated data). I was looking at the number returned in SQLERRD (3) and see if it worked for fetch only cursors and not just updates.

Re: Count of rows returned by a cursor

PostPosted: Fri Mar 12, 2010 2:41 pm
by GuyC
sqlerrd(3) does not work for cursors.
In DB2 9 you can use OLAP functions.

Re: Count of rows returned by a cursor

PostPosted: Fri Mar 12, 2010 9:36 pm
by ctrevino
Thanks, Guy. Good to know.