Solved

ASP sql server recordcount

Posted on 2010-11-11
5
516 Views
Last Modified: 2012-08-14
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?
0
Comment
Question by:Bob Schneider
5 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 125 total points
ID: 34117831

This should work

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

or you can use a function as well
0
 
LVL 23

Assisted Solution

by:Rajkumar Gs
Rajkumar Gs earned 250 total points
ID: 34117854
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
 
LVL 23

Assisted Solution

by:Rajkumar Gs
Rajkumar Gs earned 250 total points
ID: 34117859
@@rowcount will return total number of records in the query that executed just before

Raj
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 125 total points
ID: 34117874
0
 

Author Closing Comment

by:Bob Schneider
ID: 34119218
Very helpful!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now