ASP sql server recordcount

I want to get the number of records in a recordset using a stored procedure.  The recordcount approach has been returning (-1) since i converted from dynamic sql in the web page to a stored procedure.  What is the best way to get the recordcount from the stored procedure?
Bob SchneiderCo-OwnerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Ephraim WangoyaConnect With a Mentor Commented:

This should work

CREATE PROCEDURE GetRecordCount
(
      @RecordCount bigint OUTPUT
)
AS
      SELECT
            @RecordCount = COUNT(*)
      FROM
            TABLENAME

or you can use a function as well
0
 
Rajkumar GsConnect With a Mentor Software EngineerCommented:
You can @@rowcount to return the count of records.
Check the attached code

 
CREATE PROCEDURE YourStoredProcedure
(
      @RecordCount bigint OUTPUT
)
AS
begin
      SELECT *  FROM TABLENAME


     SET @RecordCount = @@rowcount 

end
go

Open in new window



Raj


0
 
Rajkumar GsConnect With a Mentor Software EngineerCommented:
@@rowcount will return total number of records in the query that executed just before

Raj
0
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
0
 
Bob SchneiderCo-OwnerAuthor Commented:
Very helpful!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.