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)
 count of distinct columns

Author  Topic 

kavithak.official
Starting Member

7 Posts

Posted - 2010-11-26 : 00:54:54
I have a table T that has few columns.
I am interested in count of distinct of (col1 and col2)
Note : col1 is of binary datatype where as col2 is of datetime datatype.

This does not just happen if you use
(count(distinct col1, col2))>0 doesn work
(count(distinct col1+col2))>0 doesn work

I want to find out the count when it is greater than 0.

Please provide your inputs on this issue.

thanks and regards,
Kavitha K

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-26 : 09:35:02
select col1,col2,count(*) from table
group by col1,col2

Madhivanan

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

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-11-26 : 09:38:48
Not clear what you want - madhivanan's query gives the number of rows for each col1, col2

This give the number of distinct col1,col2 entries
select count(*)
from
(
select distint col1, col2 fro tbl
) a


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -