DoughBoy
asked on
Get total number of records but not all records based on an SQL query
Hi,
How do I make an SQL statement retrieve JUST the first 50 rows out of a table but also return the total count of rows that may exist, maybe 400? Should they be two different SQL statments? If so, what would be both statements?
Thanks
DoughBoy
How do I make an SQL statement retrieve JUST the first 50 rows out of a table but also return the total count of rows that may exist, maybe 400? Should they be two different SQL statments? If so, what would be both statements?
Thanks
DoughBoy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think 2 sql statement should be the best, but run using a stored procedure, where 1 output parameter would be used to return the total number of records...
Option 2: (not recommended)
select top 50 a.*,b.totcount
from table a, (
select coun(*) as totcount from table) b
The above query retrieves the top 50 rows and each row have an additional field totcount containing the total no.of rows present in the table
select top 50 a.*,b.totcount
from table a, (
select coun(*) as totcount from table) b
The above query retrieves the top 50 rows and each row have an additional field totcount containing the total no.of rows present in the table
ASKER
thanks!