SQLTeam.com | Weblogs | Forums

SQL Query to COUNT Records Returned

Greetings from the Newbie,

I have a SQL statement that returns the records I need.

I want to count the number of records returned by the statement.

I have placed COUNT (*) AS 'Records' in the SELECT statement, now the statement returns error.

How do I return the value of the count in the grid?

Thank you.

Looks like you did the correct thing. Without the error it's hard to guess. Maybe you are ordering? If you post your query and error message we can help you.

If you want a column that has the total number of rows - and will be the same for every row in the results, then change it to: COUNT(*) OVER()

If you want totals - then you need to group the data according to your requirements. Then you can use any aggregate functions on the data as needed. You can also utilize GROUPING SETS to include sub-totals and rollups.

1 Like

Awesome, that worked for my needs, THANK YOU!

Would a simple SELECT @@ROWCOUNT do the trick here? The OP did say "I have A SQL statement".