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)
 To get count of selected rows in a table using CASE statemen

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-12 : 07:48:47
sql_geek writes "I have written a query using inner query loginc to get selected count of rows based on the criteria provided, however, the query is not the best perfomance wise when it comes to big tables as it takes more resources.

I know that using CASE statements to get the count of rows should take less resources. I am however having issue doing group by in the query using CASE statement. Anybody has an input as how this can be done using CASE statements.

thanks"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-12 : 07:51:57
Is this?

Select sum(case when col='somevalue' then 1 else 0 end) from your table

Madhivanan

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

- Advertisement -