Log in
::
Register
::
Not logged in
Search:
Home
Articles
Editorials
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Advertise
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
Need to add a FY Dates Table
Need to add a FY Dates Table
Rate Topic
Display Mode
Topic Options
Author
Message
marty.seed
marty.seed
Posted Tuesday, November 03, 2009 12:21 PM
SSC 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
GSquared
GSquared
Posted Tuesday, November 03, 2009 12:39 PM
SSCertifiable
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
Luke L
Luke L
Posted Tuesday, November 03, 2009 12:58 PM
SSCrazy
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
lmu92
lmu92
Posted Tuesday, November 03, 2009 1:30 PM
SSCommitted
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
marty.seed
marty.seed
Posted Tuesday, November 03, 2009 2:50 PM
SSC 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
marty.seed
marty.seed
Posted Thursday, November 05, 2009 10:36 AM
SSC 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
lmu92
lmu92
Posted Thursday, November 05, 2009 11:54 AM
SSCommitted
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
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2009 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use