|
|
Question : getting the total number of rows return added to my dataset using group by
|
|
I'm grouping on a table and I need to get the number of rows returned. What's the best way to get a summary total of the records that have met my Group by/having criteria? Do I need to write the records to a temp dataset after they have been group by/having processed, then loop through the temp dataset and count the records? Is there a better way of doing this. I need to get a summary total of the # of records my "group by/having" clause has created. I want to print this total on my report that's reading the dataset. But I don't want to do it in the report.
|
Answer : getting the total number of rows return added to my dataset using group by
|
|
After running the query, you can do this:
Select count (*) as "row count" from (select ) as t
For some reason, the final table alias "as t" is required. or select @@rowcount
If you need to use the value later, you can put it in a variable:
set @rows = @@rowcount
also; Refer to @@ROWCOUNT in SQL Server Books Online. If you are using ADO in your application, then you can use the recordset's RecordCount property to get the value at the client side.
|
|
|
|