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 2005 Forums
 Transact-SQL (2005)
 Only Count Rows With Values

Author  Topic 

paultervit
Starting Member

10 Posts

Posted - 2008-07-09 : 09:43:48
Hello All
Is it possible to run a count on cells that have values only eg

I have the following table

PC TD
1 34
1 35
2 36
2 NULL
3 NULL
3 NULL

I would like to run a query to get the following back

PC COUNT
1 2
2 1
3 NULL

Is this possible?

Thanks

Paul

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-09 : 09:46:19
[code]
select PC, count(TD)
from table
group by PC
[/code]

You want PC 3 Count 0 to show as NULL ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

paultervit
Starting Member

10 Posts

Posted - 2008-07-09 : 10:05:47
Thanks again khtan.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-09 : 11:53:31
Count never returns NULL. if you want NULL in result, you need to use NULLIF to convert 0s to NULL.
Go to Top of Page
   

- Advertisement -