Solved

How do I Fiscal implement a Fiscal Week # Function From Table with Dates

Posted on 2008-06-11
7
1,285 Views
Last Modified: 2011-09-20
Hello -
We have a new table format for fiscal year 2009. I used to be able to pull the fiscal week no. from 1-52. Now, I will need a function in the queries to calculate the fiscal week no. How do I do that based on the data  below? The fiscal week below represents the fiscal week number in the month, not the fiscal week no. for the year which I also need. Thanks!

FWeekNo.      FMonthNo.      FiscalYear      FiscalWeekStartDate      FiscalWeekEndDate
1      1      2009      6/28/2008 0:00      7/4/2008 23:59
2      1      2009      7/5/2008 0:00      7/11/2008 23:59
3      1      2009      7/12/2008 0:00      7/18/2008 23:59
4      1      2009      7/19/2008 0:00      7/25/2008 23:59
5      1      2009      7/26/2008 0:00      8/1/2008 23:59
1      2      2009      8/2/2008 0:00      8/8/2008 23:59
2      2      2009      8/9/2008 0:00      8/15/2008 23:59
3      2      2009      8/16/2008 0:00      8/22/2008 23:59
4      2      2009      8/23/2008 0:00      8/29/2008 23:59
1      3      2009      8/30/2008 0:00      9/5/2008 23:59
2      3      2009      9/6/2008 0:00      9/12/2008 23:59
3      3      2009      9/13/2008 0:00      9/19/2008 23:59
4      3      2009      9/20/2008 0:00      9/26/2008 23:59
0
Comment
Question by:savetheday
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:sbagireddi
ID: 21764383
select datepart(week,FiscalWeekStartDate  ) from Table    
0
 

Author Comment

by:savetheday
ID: 21764787
Thanks.
This returns the calendar week of the fiscalweekstartdate. I need the fiscal week. For example fiscalweekstartdate of 2008-06-28 00:00:00 is the 26th calendar week, but the 1st fiscal week.
I need a function that returns the fiscal week starting from this date and carrying to week 53 as of
2009-06-27 00:00:00
0
 
LVL 8

Expert Comment

by:sbagireddi
ID: 21764977
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 60

Accepted Solution

by:
chapmandew earned 150 total points
ID: 21765400
No reason to create a function for it....just use a dates table and use a simple lookup...in it, you can add fields for your fiscal week start date and end date so if you ever have to query for them you won't have any complex functions to deal with (depending on if your fiscal year & weeks are complex).

http://www.zdnetasia.com/techguide/database-management/0,3800010795,62041605,00.htm
0
 

Author Comment

by:savetheday
ID: 21773008
sbagireddi -

Would you give me an example of how to use this if our fiscal year always starts in July, and the fiscal week always starts on Saturday. That is, do I need to change anything in the function? Today's date is returning 200750 as is. The week is correct, but not 2007.

chapmandew -
This is a good solution. Unfortunately for dates we cannot add tables for exactly the reason you mentioned - glitches in tables would wreak havoc on reports (not picking up leap years for example), so our IT dept has to publish an official table and we work with it from there.
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21773081
Have your IT dept publish it then...its all in the creation of the table.  If you create it with leap years then they will be included.
0
 
LVL 8

Assisted Solution

by:sbagireddi
sbagireddi earned 150 total points
ID: 21773883
You will need to hack the function above to suit your needs.
If thats too much of a hassle I would just go with a calendar table as suggested by chapmandew above.

I found another example of it:

http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question