Solved

ASP sql server recordcount

Posted on 2010-11-11
5
521 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

623 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