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 2005 Forums
 Transact-SQL (2005)
 sql help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-12-16 : 14:09:51
i have a table that has number of messages entered each day per affiliate.

so table is
messages
fields - date,affiliatecode

How can I query by affiliatecode,startdate and end date and get a list per week of the number of messages grouped by date?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-16 : 14:15:42
[code]
SELECT affiliatecode,DATEADD(dd,DATEDIFF(dd,0,date),0) AS date,COUNT(*)
FROM messages
WHERE date BETWEEN @startdate AND dateadd(dd,1,@enddate)
GROUP BY affiliatecode,DATEADD(dd,DATEDIFF(dd,0,date),0)
[/code]
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-12-16 : 14:29:56
but I want it to show a list per week (not day)?
where does this show per week
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-12-17 : 05:54:52
I modified this to weeks but is there anyway for it to show all weeks even 1 with 0 entries and just show a 0?
Go to Top of Page
   

- Advertisement -