SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 
        
Home       Members    Calendar    Who's On



Need to add a FY Dates Table Expand / Collapse
Author
Message
Posted Tuesday, November 03, 2009 12:21 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 2:19 PM
Points: 48, Visits: 97
Hey all,

I have been tasked with adding a table that stores all the dates for our fiscal years.

I want to add each year at a time


Our problem stems with the fact that our fiscal year starts at strange times. For instance I want to add FY 2008, the start date is 12/02/07.

Here are the things I am trying to add and the table created...

CREATE TABLE [dbo].[Calendar](
[dt] [smalldatetime] NOT NULL,
[isWeekday] [bit] NULL,
[isHoliday] [bit] NULL,
[Y] [smallint] NULL,
[FY] [smallint] NULL,
[FYQ] [tinyint] NULL,
[FYM] [tinyint] NULL,
[D] [tinyint] NULL,
[DW] [tinyint] NULL,
[monthname] [varchar](9) NULL,
[dayname] [varchar](9) NULL,
[WeekNumber] [tinyint] NULL,
PRIMARY KEY CLUSTERED
(
[dt] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

While I can get the majority of this data into the table what I am really having a hard time with is finding the fy week number, fy month number.

I need 12/02/07 to be week 1 and month 1 if that makes more sense...

Any help is greatly appreciated!
Post #813143
Posted Tuesday, November 03, 2009 12:39 PM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 1:27 PM
Points: 7,838, Visits: 4,282
Will DateDiff(Week) from the start date of the year give you the week?

- GSquared

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #813150
Posted Tuesday, November 03, 2009 12:58 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, November 12, 2009 9:20 AM
Points: 2,069, Visits: 2,959
Are your storing every date in the year or just start and end dates for Fiscal months and such?

I ask because the Datediff week calculation will not work correctly...

You may need to do datediff(week, date, date) + 1

Because 2007-12-02 and 2007-12-03 will return 0 because they are in the same week.

-Luke.


To help us help you read this

For better help with performance problems please read this
Post #813171
Posted Tuesday, November 03, 2009 1:30 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 3:59 PM
Points: 1,747, Visits: 2,495
What is the business rule for the beginning of a new fiscal year (always first Sunday of December?)
What is the business rule for defining a fiscal month? Is it based on week pattern (like 4-4-5-4-4-5 a.s.o.) or when does a new fiscal month start?




Lutz

A pessimist is an optimist with experience.

How to get fast answers to your question
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs
Post #813193
Posted Tuesday, November 03, 2009 2:50 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 2:19 PM
Points: 48, Visits: 97
I took your suggestions and was able to change it so:

declare @min datetime
set @min=(select MIN(DATEFULL)
from Calendar)
Update Calendar
SET WeekNumber=DateDiff(week,@min,datefull)+1
Post #813261
Posted Thursday, November 05, 2009 10:36 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 2:19 PM
Points: 48, Visits: 97
Hey Imu,

Thought I had this correct but seems like it is more how you have it

Here is the cunundrum.
Our fiscal year ends the Saturday after the last Friday or November, the next Fiscal year start the immediate Sunday.

If a week has wed-sat falling in the next month it is considered a new week, new month.

The business rule for defining a Fiscal Month is as you have it below
(like 4-4-5-4-4-5 a.s.o.)
Post #814429
Posted Thursday, November 05, 2009 11:54 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 3:59 PM
Points: 1,747, Visits: 2,495
marty.seed (11/5/2009)

...If a week has wed-sat falling in the next month it is considered a new week, new month.

The business rule for defining a Fiscal Month is as you have it below
(like 4-4-5-4-4-5 a.s.o.)


Sounds like an either/or to me...
I'm not sure if it's possible to meet both criteria all the time (haven't tried it yet).
Could you please clarify?




Lutz

A pessimist is an optimist with experience.

How to get fast answers to your question
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs
Post #814470
« Prev Topic | Next Topic »


Permissions Expand / Collapse