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 |
|
meberg66219
Yak Posting Veteran
65 Posts |
Posted - 2010-12-13 : 13:18:30
|
| SELECT DATENAME(weekday, DateAdded) AS AddDate, DATEPART(week, DateAdded) AS WeekNumber, DATEPART(year, DateAdded)AS YearNumber, COUNT(SyStudentID) AS NewStudentsFROM dbo.SyStudentWHERE DateAdded >=dateadd(day,datediff(day,0,GetDate())- 7,0)GROUP BYDateAddedORDER BYYearNumber,WeekNumber,AddDateWhat I get as a return is:AddDate=FridayWeekNumber=50YearNumber=2010New Students=2AddDate=FridayWeekNumber=50YearNumber=2010NewStudents=1and this goes on for however many entries there were for the dayWhat I need is this type of data:AddDate=FridayWeekNumber=50YearNumber=2010NewStudents=24AddDate=ThursdayWeekNumber=50YearNumber=2010NewStudents=22Etc.I need the query to count the total number of students per day and report that back instead of the same day 25 times with a count total of 1 or 2. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-12-13 : 13:36:14
|
| [code]GROUP BY DATENAME(weekday, DateAdded), DATEPART(week, DateAdded), DATEPART(year, DateAdded)[/code] |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-13 : 13:37:21
|
Try:GROUP BY dateadd(day,datediff(day,0,DateAdded),0)That will strip the time part in your group by. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
revdnrdy
Posting Yak Master
220 Posts |
Posted - 2010-12-13 : 13:38:05
|
quote: Originally posted by meberg66219 SELECT DATENAME(weekday, DateAdded) AS AddDate, DATEPART(week, DateAdded) AS WeekNumber, DATEPART(year, DateAdded)AS YearNumber, COUNT(SyStudentID) AS NewStudentsFROM dbo.SyStudentWHERE DateAdded >=dateadd(day,datediff(day,0,GetDate())- 7,0)GROUP BY DateAddedORDER BY YearNumber, WeekNumber, AddDateWhat I get as a return is:AddDate=FridayWeekNumber=50YearNumber=2010New Students=2AddDate=FridayWeekNumber=50YearNumber=2010NewStudents=1and this goes on for however many entries there were for the dayWhat I need is this type of data:AddDate=FridayWeekNumber=50YearNumber=2010NewStudents=24AddDate=ThursdayWeekNumber=50YearNumber=2010NewStudents=22I need the query to count the total number of students per day and report that back instead of the same day 25 times with a count total of 1 or 2.
Would something like this work? I use it to count the number of help desk tickets created daily where I work. Perhaps you can modify it?Select count(DATENAME(weekday, DateAdded) AS AddDate), DATEPART(week, DateAdded) AS WeekNumber, DATEPART(year, DateAdded)AS YearNumber, SyStudentID AS NewStudents from dbo.SyStudent group by AddDate |
 |
|
|
meberg66219
Yak Posting Veteran
65 Posts |
Posted - 2010-12-13 : 13:42:02
|
| Thank you!!!! That worked perfectly! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-13 : 13:44:01
|
Hm...All given solutions? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-12-13 : 13:58:45
|
quote: Originally posted by webfred Hm...All given solutions? No, you're never too old to Yak'n'Roll if you're too young to die.
Yours and mine ought to anyway lol |
 |
|
|
meberg66219
Yak Posting Veteran
65 Posts |
Posted - 2010-12-14 : 13:33:50
|
| Yes Russell and WebFred's solutions worked. |
 |
|
|
|
|
|
|
|