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 |
|
Rheinhardt
Yak Posting Veteran
66 Posts |
Posted - 2011-11-15 : 08:46:02
|
| HI,I have the following data:Date by Day,Product,Customer,qty14/11/2011,ProdA,Costb,1014/11/2011,ProdA,Costb,1516/11/2011,Prodb,Costb,10Thereore in week 14/11-19/11 there was 2 deliveries...2 days in the week.I need too calculate how many times (frequency) a delivery was made by week.So how many days in a week was there a delievry.(By Customer)I have a Week table as well:Weeknr,weekstartdate,weekenddatePlease help |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-11-15 : 08:52:56
|
| select t.customer, w.weeknbr, num = count(*), NumDays = count(distinct t.date)from tbl tjoin weektbl won t.date between w.weekstartdate and w.weekenddategroup by t.customer, w.weeknbr==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
Rheinhardt
Yak Posting Veteran
66 Posts |
Posted - 2011-11-15 : 09:44:06
|
| Thanks |
 |
|
|
|
|
|
|
|