Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Count & Recordset

Posted on 1999-07-27
7
Medium Priority
?
748 Views
Last Modified: 2008-03-17
How do I count the rows returned by an execute command?

Here is the command:
EXECUTE GetItemDetail 1

Here is the sotred procedure:
CREATE PROCEDURE GetItemDetail
      @ItemID      as Int
AS
      SELECT * FROM ForSale WHERE ID= @ItemID

I need to get the recordset & the Count back
0
Comment
Question by:MasseyM
[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
  • 2
7 Comments
 
LVL 7

Accepted Solution

by:
spiridonov earned 200 total points
ID: 1096876
There are two options:
If the application, that you use to execute sp supports multiple result sets you can add SELECT @@ROWCOUNT at the end of sp - it will return recordset you are expecting and an additional recordset consisting of one record of one field containing count of the first recordset.
If the application can receive output parameters from sp, you can declare your sp as
CREATE PROCEDURE GetItemDetail
@ItemID as Int
@rs_count as int OUTPUT
AS
SELECT * FROM ForSale WHERE ID= @ItemID
SELECT @rs_count=@@ROWCOUNT
and analyse output parameter rs_count after execution.
0
 
LVL 10

Author Comment

by:MasseyM
ID: 1096877
the application is ASP
0
 
LVL 10

Author Comment

by:MasseyM
ID: 1096878
how do I call the EXECUTE?  I cannot get it o find the @rs_count field.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 7

Expert Comment

by:spiridonov
ID: 1096879
>>how do I call the EXECUTE?  
How do you call it now?

>>I cannot get it o find the @rs_count field.
I don't  quite understand what you mean?? @rs_count is an output parametere of the sp, that you define. Where do you want to find it?
0
 
LVL 10

Author Comment

by:MasseyM
ID: 1096880
I use this:

Set ItemRS = Conn.Execute "GetItemDetail 1"


then to gain accessto the fields, I use
ItemRS("FieldName")

I basically want to do this:
IF The recordcount = 1 then
  Do while not ItemRS.EOF
    display all records here
  ItemRs.MoveNext
  Loop
Else
  no records found
End If
0
 
LVL 10

Author Comment

by:MasseyM
ID: 1096881
I use this:

Set ItemRS = Conn.Execute "GetItemDetail 1"


then to gain accessto the fields, I use
ItemRS("FieldName")

I basically want to do this:
IF The recordcount = 1 then
  Do while not ItemRS.EOF
    display all records here
  ItemRs.MoveNext
  Loop
Else
  no records found
End If
0
 
LVL 10

Author Comment

by:MasseyM
ID: 1096882
I found another command in ADO.  It is called NextRecordset.  This moves you to the second recordset that is produced.  I will accept your answer as it provided me with something.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

670 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