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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 count distinct values
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Aged Yak Warrior

723 Posts

Posted - 01/08/2013 :  09:12:30  Show Profile  Visit pelegk2's Homepage  Send pelegk2 an ICQ Message  Reply with Quote
i have table with :
i want to count for each day
1)how many rows there are
2)how many distinct personalid in a day

what the best way to do it?

Flowing Fount of Yak Knowledge

United Kingdom
3385 Posts

Posted - 01/08/2013 :  09:26:57  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
select count(*), count(distinct personalid), date
from tbl
group by date

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

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/08/2013 :  23:49:01  Show Profile  Reply with Quote
does date field store timepart too? if yes,

select count(*), count(distinct personalid),  dateadd(dd,datediff(dd,0,[date]),0)
from tbl
group by dateadd(dd,datediff(dd,0,[date]),0)

SQL Server MVP

Go to Top of Page

Aged Yak Warrior

723 Posts

Posted - 01/09/2013 :  03:58:35  Show Profile  Visit pelegk2's Homepage  Send pelegk2 an ICQ Message  Reply with Quote
10x all
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000