Fiscal Dates

  • My company wants to create a Financial Calendar Table which contains only the Fiscal Dates. The requirements is ti populate it with the following columns:

    - DateKey

    - Fiscal_Year

    - Fiscal_Month

    - Fiscal_Week

    - Fiscal Week_Start_Date

    - Fiscal_Week_End_Date

    The rules for these columns are:

    - DateKey has to be in the format YYYYMMDD

    - Weeks begin from Monday - Sunday

    - Financial Year begins on 01/Jul

    - Financial Week begins from Monday , which means if 01/Jul falls on any other days, then we have to take the Monday of that week as the beginning of the financial week. e.g. If 01/Jul falls on Wednesday, then the beginning of week is 29/06

    Can someone help me with this script?

  • rka (9/2/2012)


    DateKey has to be in the format YYYYMMDD

    In SQL Server, that's a pretty insane requirement because that would make a character based date. Since you're using SQL Server 2008, you should either use DATETIME or DATE datatypes for such a thing.

    I strongly recommmend you talk to the people that designed the table and suggest that they should probably change it.

    As for actually building the table... what have you tried that's not working?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (9/3/2012)


    rka (9/2/2012)


    DateKey has to be in the format YYYYMMDD

    In SQL Server, that's a pretty insane requirement because that would make a character based date. Since you're using SQL Server 2008, you should either use DATETIME or DATE datatypes for such a thing.

    I strongly recommmend you talk to the people that designed the table and suggest that they should probably change it.

    As for actually building the table... what have you tried that's not working?

    Jeff I agree its pretty insane,

    But I've seen this especially if the YYYYMMDD is converted to an INT eg 20120101 = 20,120,101.

    Its been a frequent topic of discussion on various DW projects that I've worked on, prior to the Date Data type most of the calendar dims used the DateTime with the PK/SK column a CAST(CalendarDate as Int), again a pretty nasty way of doing this especially if you have a time element due to the rounding issues.

    However, since 2008 I've been converted to Date Data type as the PK/SK and it seems to work very well.

    _________________________________________________________________________
    SSC Guide to Posting and Best Practices

  • Jason-299789 (9/4/2012)


    Jeff Moden (9/3/2012)


    rka (9/2/2012)


    DateKey has to be in the format YYYYMMDD

    In SQL Server, that's a pretty insane requirement because that would make a character based date. Since you're using SQL Server 2008, you should either use DATETIME or DATE datatypes for such a thing.

    I strongly recommmend you talk to the people that designed the table and suggest that they should probably change it.

    As for actually building the table... what have you tried that's not working?

    Jeff I agree its pretty insane,

    But I've seen this especially if the YYYYMMDD is converted to an INT eg 20120101 = 20,120,101.

    Its been a frequent topic of discussion on various DW projects that I've worked on, prior to the Date Data type most of the calendar dims used the DateTime with the PK/SK column a CAST(CalendarDate as Int), again a pretty nasty way of doing this especially if you have a time element due to the rounding issues.

    However, since 2008 I've been converted to Date Data type as the PK/SK and it seems to work very well.

    NP. Thanks for the feedback. I have to ask again, though... what have you tried that isn't working in your efforts to build this table?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jason-299789 (9/4/2012)


    Jeff Moden (9/3/2012)


    rka (9/2/2012)


    DateKey has to be in the format YYYYMMDD

    In SQL Server, that's a pretty insane requirement because that would make a character based date. Since you're using SQL Server 2008, you should either use DATETIME or DATE datatypes for such a thing.

    I strongly recommmend you talk to the people that designed the table and suggest that they should probably change it.

    As for actually building the table... what have you tried that's not working?

    Jeff I agree its pretty insane,

    But I've seen this especially if the YYYYMMDD is converted to an INT eg 20120101 = 20,120,101.

    Its been a frequent topic of discussion on various DW projects that I've worked on, prior to the Date Data type most of the calendar dims used the DateTime with the PK/SK column a CAST(CalendarDate as Int), again a pretty nasty way of doing this especially if you have a time element due to the rounding issues.

    However, since 2008 I've been converted to Date Data type as the PK/SK and it seems to work very well.

    A "DW" is a data warehouse which is an OLAP-type database, and these rules and keys might make sense there, because an OLAP database has different goals than an OLTP database, and thus a different (though related) modelling methodology, and therefore a different set of normal rules.

    An OLAP database is designed to facilitate reporting, at the expense of other things, like diskspace and being able to maintain the data in real-time. OLTP databases on the other hand are designed to facilitate real-time data updates while insuring consistency and still be able to report on the data.

    Because of these differences in goals, OLAP databases will frequently have highly redundant multi-discriminating key structures, like the one you suggest, because they can greatly facilitate reporting and summarization. But they are an anethema to an OLTP database because they introduce all kinds of problems with maintaining the consistency of the data and keys when trying to incrementally keep it up-to-date in real time.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • RBarryYoung (9/4/2012)


    Jason-299789 (9/4/2012)


    Jeff Moden (9/3/2012)


    rka (9/2/2012)


    DateKey has to be in the format YYYYMMDD

    In SQL Server, that's a pretty insane requirement because that would make a character based date. Since you're using SQL Server 2008, you should either use DATETIME or DATE datatypes for such a thing.

    I strongly recommmend you talk to the people that designed the table and suggest that they should probably change it.

    As for actually building the table... what have you tried that's not working?

    Jeff I agree its pretty insane,

    But I've seen this especially if the YYYYMMDD is converted to an INT eg 20120101 = 20,120,101.

    Its been a frequent topic of discussion on various DW projects that I've worked on, prior to the Date Data type most of the calendar dims used the DateTime with the PK/SK column a CAST(CalendarDate as Int), again a pretty nasty way of doing this especially if you have a time element due to the rounding issues.

    However, since 2008 I've been converted to Date Data type as the PK/SK and it seems to work very well.

    A "DW" is a data warehouse which is an OLAP-type database, and these rules and keys might make sense there, because an OLAP database has different goals than an OLTP database, and thus a different (though related) modelling methodology, and therefore a different set of normal rules.

    An OLAP database is designed to facilitate reporting, at the expense of other things, like diskspace and being able to maintain the data in real-time. OLTP databases on the other hand are designed to facilitate real-time data updates while insuring consistency and still be able to report on the data.

    Because of these differences in goals, OLAP databases will frequently have highly redundant multi-discriminating key structures, like the one you suggest, because they can greatly facilitate reporting and summarization. But they are an anethema to an OLTP database because they introduce all kinds of problems with maintaining the consistency of the data and keys when trying to incrementally keep it up-to-date in real time.

    BWAA-HAAA!!!! Is that the long version for "storing dates as INTs or VARCHARs sucks"??? 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (9/4/2012)


    RBarryYoung (9/4/2012)


    Jason-299789 (9/4/2012)


    Jeff Moden (9/3/2012)


    rka (9/2/2012)


    DateKey has to be in the format YYYYMMDD

    In SQL Server, that's a pretty insane requirement because that would make a character based date. Since you're using SQL Server 2008, you should either use DATETIME or DATE datatypes for such a thing.

    I strongly recommmend you talk to the people that designed the table and suggest that they should probably change it.

    As for actually building the table... what have you tried that's not working?

    Jeff I agree its pretty insane,

    But I've seen this especially if the YYYYMMDD is converted to an INT eg 20120101 = 20,120,101.

    Its been a frequent topic of discussion on various DW projects that I've worked on, prior to the Date Data type most of the calendar dims used the DateTime with the PK/SK column a CAST(CalendarDate as Int), again a pretty nasty way of doing this especially if you have a time element due to the rounding issues.

    However, since 2008 I've been converted to Date Data type as the PK/SK and it seems to work very well.

    A "DW" is a data warehouse which is an OLAP-type database, and these rules and keys might make sense there, because an OLAP database has different goals than an OLTP database, and thus a different (though related) modelling methodology, and therefore a different set of normal rules.

    An OLAP database is designed to facilitate reporting, at the expense of other things, like diskspace and being able to maintain the data in real-time. OLTP databases on the other hand are designed to facilitate real-time data updates while insuring consistency and still be able to report on the data.

    Because of these differences in goals, OLAP databases will frequently have highly redundant multi-discriminating key structures, like the one you suggest, because they can greatly facilitate reporting and summarization. But they are an anethema to an OLTP database because they introduce all kinds of problems with maintaining the consistency of the data and keys when trying to incrementally keep it up-to-date in real time.

    BWAA-HAAA!!!! Is that the long version for "storing dates as INTs or VARCHARs sucks"??? 😀

    8^Þ

    (heh)

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • These two articles might give you a method of doing what you desire.

    http://www.sqlservercentral.com/articles/function/67046/

    http://www.sqlservercentral.com/articles/function/68323/

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply