Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Question about T-SQL: grouping data by week
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00636665
Message ID:
00636677
Views:
20
In this case you still use DATEPART()
Select Acct, Item, DATEPART(week, InvDate) AS week, SUM(QtyShipped)
FROM mytable 
GROUP BY Acct, Item, DATEPART(week, InvDate)
Using SET DATEFIRST you can change the first day of the week.

Syntax

>Hi, Sergey...
>
>Thanks for your answer - unfortunately, I think I may have worded the question incorrectly.
>
>I'm basically trying to collapse shipments down to the week. I can't really explain this without giving an example...
>
>Monday, the 3rd: 10 units shipped
>Friday, the 7th: 11 units shipped
>
>Monday, the 10th, 6 units shipped
>Tuesday, the 11th, 21 units shipped
>Saturday, the 15th, 3 units shipped
>
>I'm trying to write a T-SQL query so that I can produce this result:
>
>Week ending Saturday the 8th: 21 units shipped
>Week ending Saturday the 15th: 30 units shipped
>
>Also, the week ending date for the query could be a Saturday, but could also be another day of the week. And maybe DATEPART is still the answer, though reading BOL about how to use it has me a bit confused.
>
>Thanks,
>Kevin
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform