?
Solved

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

Posted on 2008-06-11
7
Medium Priority
?
1,294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

764 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