Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

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

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, February 03, 2012 1:58 PM
Points: 89, Visits: 180
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


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 8:55 AM
Points: 13,529, Visits: 8,088
Will DateDiff(Week) from the start date of the year give you the week?

- GSquared, RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"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: Yesterday @ 2:19 PM
Points: 2,886, Visits: 5,751
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


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 4:50 PM
Points: 6,532, Visits: 11,553
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
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #813193
Posted Tuesday, November 03, 2009 2:50 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, February 03, 2012 1:58 PM
Points: 89, Visits: 180
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 Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, February 03, 2012 1:58 PM
Points: 89, Visits: 180
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


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 4:50 PM
Points: 6,532, Visits: 11,553
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
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #814470
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse