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
 General SQL Server Forums
 New to SQL Server Programming
 Weekly Spend

Author  Topic 

velvettiger
Posting Yak Master

115 Posts

Posted - 2009-10-12 : 15:32:26
Hi everyone,

Is there a special function that can be used to extract customers weekly spend. I have a database for which show individual transaction and their dates. My teacher normally ask for extracts done on a yearly basis so this is pretty new to me. Does any one have any ideas?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-10-12 : 15:57:38
Perhaps something like this - this assumes weeks start on a Monday:

select dateadd(week, datediff(week, '1950-01-02', <dateCol>), '1950-01-02')
,sum(<spendingCol>) as weeklySpending
from <yourTable>
where <dateCol> >= '<Beginning Date>'
and <dateCol> <= '<Ending Date>'
group by datediff(week, '1950-01-02', <dateCol>)


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -