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 |
|
mattastic
Starting Member
15 Posts |
Posted - 2005-01-24 : 10:46:26
|
| Hi,I've made a hit counter that inserts the number of hits into a db each day, there is also a date column where the date is inserted using getdate().I use the following code to get weekly totals, but I would like to get the date that the week commenced, is this possible?Select Count(*) As myCountFrom myTableGroup By DatePart(week, mydateColumn)Thanks for your help |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-01-24 : 11:27:50
|
Well that dependsBOLquote: SET DATEFIRSTSets the first day of the week to a number from 1 through 7.SyntaxSET DATEFIRST { number | @number_var } Argumentsnumber | @number_varIs an integer indicating the first day of the week, and can be one of these values.
Brett8-) |
 |
|
|
mattastic
Starting Member
15 Posts |
Posted - 2005-01-25 : 04:40:01
|
| Thanks for your replyCould you give me an example of how to use it with my query?My sql is very bad |
 |
|
|
mattastic
Starting Member
15 Posts |
Posted - 2005-01-25 : 05:46:16
|
| Hi,I've managed to display the total hits for each week,which begins ona Monday:SET DATEFIRST 1Select sum(webcount) As myCountFrom counthistoryGroup By DatePart(week, countdate)How can I display the actual date for each monday? |
 |
|
|
guidomarcel
Starting Member
5 Posts |
Posted - 2005-01-25 : 06:24:43
|
| Hi,this is my suggestion (assuming that there is a week column and a mydateColumn):Select Count(*)As myCount, min(mydateColumn) From myTableGroup By weekRegardsGuidoMarcelThe free SQL Code Formatter on www.sqlinform.com |
 |
|
|
|
|
|