Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Getting total rows in a subquery

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-12-12 : 07:19:56
Jonas writes "Jonas writes "Hi,

I need to return total rows in a subquery.

Example.

SELECT col1, col2, TotalRowsInSubQuery FROM
(
SELECT col1, col2 FORM tbl1
) as mySubQueryTable
WHERE col1 = 2


TotalRowsInSubQuery should return the amount of rows affected by the select in the subquery.
(if mySubQueryTable has 10posts, TotalRowsInSubQuery should also be 10)

TIA!"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-12 : 07:33:28
You need to make use of Count

SELECT col1, col2, TotalRowsInSubQuery FROM
(
SELECT col1, col2,Count(*) as TotalRowsInSubQuery FORM tbl1 group by col1,col2
) as mySubQueryTable
WHERE col1 = 2


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -