View previous topic :: View next topic
|
Author |
Message |
gangapd
New User
Joined: 04 Oct 2016 Posts: 2 Location: India
|
|
|
|
Hi,
We have a console application written in .NET accessing DB2 tables using stored procedures. I need to know the # of rows returned by SQL query. Currently we are using SELECT COUNT (*). Is there a better way of doing this? Something like SQLERRD3 equivalent? Please help |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Is there a problem in returning SQLERRD(3) from your stored procedure, through one of the output parameters? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Quote: |
Is there a problem in returning SQLERRD(3) from your stored procedure, through one of the output parameters? |
After opening the cursor, you will get 0 for SQLERRD(3). Because, rows are fetched only after FETCH statement is executed but this may or may not be true for multi row fetch cursors so it can not be used since the fetch is done by front end.
Welcome!!
Quote: |
SELECT COUNT (*). Is there a better way of doing this? |
It looks to me that, your design is poor because if you wanted total count of the rows then you let you design change to pass you back the count from one of the parameter but you want some short cuts? what it makes difficult to get count(*) from SP to change? or why do you need that count(*) now and not before? |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Rohit Umarjikar wrote: |
After opening the cursor |
I could not find the OP mentioning that his stored procedure has a cursor in it.
EDIT : On a second thought, since multiple rows are involved, yes but still if fetch is happening outside the stored procedure, then finding the count should not be that hard. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
It is indeed a cursor otherwise for a single select query why would he need count(*)? It is better to wait otherwise to get more clarity on stated problem. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Quote: |
Currently we are using SELECT COUNT (*). Is there a better way of doing this? |
How about counting rs (ResultSet object) hasNext() condition is true? You may as well add your row processing logic in this loop.
rs.last().getRow(); may NOT always work as most sites I've worked with use third party ODBC drivers to connect to DB2. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
Back to top |
|
|
|