Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Crosstab counting

Author  Topic 

orozcoc
Starting Member

13 Posts

Posted - 2002-09-20 : 11:39:14
How would you count the number of records returned by this SP:

http://www.sqlteam.com/item.asp?ItemID=2955

Thanks a lot


robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-09-20 : 11:46:51
After you execute the procedure, the @@ROWCOUNT variable will return the number of rows that it generated (just like any other SQL statement)

Go to Top of Page

orozcoc
Starting Member

13 Posts

Posted - 2002-09-20 : 11:55:56
But if I run the Select it will return the table, now I'm running a cursor on the result table to return a paginated subset of the result to the browser, and to calculate the total pages I still need the total number of rows returned.

Thanks for all your help

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-09-20 : 12:26:54
eeeeeeeeeeeeeewwwwwwwwwwwwwwwww cursors

You can modify the cross tab procedure to return the @@ROWCOUNT, either as an output variable or a RETURN value, see here for more details:

http://www.sqlteam.com/item.asp?ItemID=2644

There are other, non-cursor methods for paging records:

http://www.sqlteam.com/SearchResults.asp?SearchTerms=paging

Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-09-20 : 12:31:49
when a SP returns a recordset to you, you get a couple of 'freebies' with it....an error code if any (@@ERROR)...and a RECORDCOUNT (@@ROWCOUNT)....


you don't have to issue any command to request them...the system calculates them for you....

SELECT * FROM CUSTOMER
(on a table with 10 customer)
will give you a recordset of 10 records AND fill the variable @@ROWCOUNT with 10...


try the statements below....
SELECT @@ROWCOUNT
SELECT * FROM CUSTOMER
SELECT @@ROWCOUNT

you will see that the @ROWCOUNT variable changes from 1 to 10 solely because of the SELECT * statement between them.


if you are calling the SP from VB....the recordset (depending on the mode (forwardonly)??? of calling the SP) will have a property of ".recordcount"...which will hold the @@ROWCOUNT value....

Go to Top of Page
   

- Advertisement -