?
Solved

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

Posted on 2008-06-11
7
Medium Priority
?
1,298 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Accepted Solution

by:
chapmandew earned 450 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 450 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

830 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