anbu
anbu

Reputation: 103

query to fetch the number of rows fetched by another query

How do I fetch the number of rows fetched by another query in SQL server:

The required value should be:

select count(*) of select * from table 

Upvotes: 0

Views: 75

Answers (3)

aok
aok

Reputation: 374

Why the nested query? If all you need is the count of rows fetched by a query, better replace everything in the SELECT clause of that query with 'SELECT COUNT(*)' thus saving on using nested queries

Query 1:

select COUNT(*) from 
(
    select col1, col2, col3
    From Table1
    WHERE <Conditions>
)as x

Query 2:

select COUNT(*)
From Table1
WHERE <Conditions>

Both the Queries should be giving the same Output.

Upvotes: 0

Darshan Rawal
Darshan Rawal

Reputation: 81

Simply Try this Query for the number of rows fetched by another query in SQL server

select temp.TblCount From
(select Count(*) As TblCount from YOURTABLE) As Temp

Upvotes: 0

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28403

Simply try

SELECT count(*) FROM 
(
 select * from yourtable
) AS A

Upvotes: 2

Related Questions