• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Week part

I have a sql query that groups on "Datepart(dw, DateField)" however in some cases the week should start of a Thrusday and end on the following wednesday. What is the best way to handle a week not starting on a Sunday?



0
craigdev
Asked:
craigdev
  • 2
1 Solution
 
gjutrasCommented:
write a scaler function that returns the week number you want and use that in your select and group by.  use a case or if statement in the function to adjust the date based on start of week day.  Let me know if you'd like help with a function to do that.
0
 
gjutrasCommented:
actually you can do it inline
Datepart(dw, DATEADD(d,3,DateField) )-- change 3 to whatever number of days past or before sunday you need
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now