Solved

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

Posted on 2008-06-11
7
1,284 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

910 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

22 Experts available now in Live!

Get 1:1 Help Now