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.
Author |
Topic |
konark
Yak Posting Veteran
60 Posts |
Posted - 2010-09-22 : 18:05:35
|
Create table DBO.TEST( vID int , vdate datetime ) Insert into dbo.TEST select 1, GETDATE()-2 union Select 2, GETDATE()-2 union Select 3, GETDATE()-4 union Select 4, GETDATE()-5 union Select 5, GETDATE()-5 union Select 6, GETDATE()-6 union Select 7, GETDATE()-7 Select CONVERT( varchar, vdate,101) ,COUNT(1) from DBO.TEST group by CONVERT( varchar, vdate,101) order by 1 desc How can i get the output ? Date count 09/19/2010 0Chandragupta MouryaTakhyashila |
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2010-09-22 : 19:06:09
|
Not following you exactly, can you explain more what you are looking to do. Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
kunal.mehta
Yak Posting Veteran
83 Posts |
Posted - 2010-09-23 : 07:24:04
|
declare @TEST table ( vID int , vdate datetime ) Insert into @TESTselect 1, GETDATE()-2unionSelect 2, GETDATE()-2unionSelect 3, GETDATE()-4unionSelect 4, GETDATE()-5unionSelect 5, GETDATE()-5unionSelect 6, GETDATE()-6unionSelect 7, GETDATE()-7declare @st as datetimedeclare @end as datetimeselect @st = MIN(vdate),@end = MAX(vdate) from @TESTprint @stprint @end;with timeslots as(select DATEADD(DAY,count1-1,@st) as ts_f from(select row_number() over (order by id desc) [count1] from sysobjects) as a where count1<(DATEDIFF(day, @st,@end))+2)Select CONVERT( varchar, ts_f,101) ,(select COUNT(*) from @TEST where CONVERT( varchar, ts_f,101) = CONVERT( varchar, vdate,101))from timeslotsgroup by CONVERT( varchar, ts_f,101)order by 1 desc |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-23 : 13:10:44
|
http://visakhm.blogspot.com/2010/02/generating-calendar-table.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|