Click here to Skip to main content
15,894,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table T1, Now I need to return whole rows and rows count in a single query
Posted
Comments
Wendelius 25-Mar-11 14:28pm    
If the issue isn't solved, could you add a little example for the original data and how you want the output. Do you actually want a running total?

try this

select column1,column2,@@ROWCOUNT as rows from table 

it will return all columns ,row count in each rows
 
Share this answer
 
v2
Comments
m@dhu 25-Mar-11 8:30am    
Use pre tags to wrap the code for better readability.
vipinsethumadhavan 25-Mar-11 8:32am    
I got a error as suquery returns more than one rows.
I have a query ,which got result as
select '' as count,col1,col2 from t1 union
select count(*) as count,'','';No problem
But issue is that first query has order clause.But Order clause can't use here
For Sql 2005 and up try this

SQL
select  *,
        rowcnt = count(*) over()
from    MyTable
 
Share this answer
 
select *, (select count(*) from table) from table

Not most optimal but works!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900