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 2000 Forums
 SQL Server Development (2000)
 SQL Group problem

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 myCount
From myTable
Group By DatePart(week, mydateColumn)

Thanks for your help

X002548
Not Just a Number

15586 Posts

Posted - 2005-01-24 : 11:27:50
Well that depends

BOL

quote:

SET DATEFIRST
Sets the first day of the week to a number from 1 through 7.

Syntax
SET DATEFIRST { number | @number_var }

Arguments
number | @number_var

Is an integer indicating the first day of the week, and can be one of these values.






Brett

8-)
Go to Top of Page

mattastic
Starting Member

15 Posts

Posted - 2005-01-25 : 04:40:01
Thanks for your reply

Could you give me an example of how to use it with my query?

My sql is very bad
Go to Top of Page

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 1
Select sum(webcount) As myCount
From counthistory
Group By DatePart(week, countdate)

How can I display the actual date for each monday?
Go to Top of Page

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 myTable
Group By week

Regards
GuidoMarcel

The free SQL Code Formatter on www.sqlinform.com
Go to Top of Page
   

- Advertisement -