Solved

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

Posted on 2008-06-11
7
1,280 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now