programming weeks

  • Hi everyone, I have to write a program for a report. The report will be as such:

    Quarter

    Week Number of Orders

    So the result will be something like this:

    Q1

    12/31/01 - 1/6/02 165

    1/7/02 - 1/13/02 318

    1/14/02 - 1/20/02 239

    and so on into the next quarters. I am not sure how I can program this. I am confused about the weeks, how can I program the number of sales in a week (our company's weeks are from Monday to Sunday). Any help would be very much appreciated. Also, the deadline is this Friday. Thank you in advance.

  • By using the DatePart T-SQL function, you can return the week number of the year of any date, so there's you a way to work with weeks. As for the different week definition, I would imagine the SET DATEFIRST will allow you to change the week definition to what you use. In your example, you would get the first and last days of the week returned by the datepart function and your number of orders.

    Something to keep in mind here, is that the Datepart function, which is generally deterministic, becomes non-deterministic due to the change issued by the Set Datefirst command.

    That should do ya....

  • You can also return quarters with Datepart. Scorpian has good advice.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

    http://www.dkranch.net

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply