Calendar Table

Does anyone know the best way to set up a calendar table? We will need a way to account for weekends and holidays when determining work days. I have been searching for some pl/sql code to do this. We are currently not using any other calendaring or using with forms. Needed mainly for reporting issues.
Please let me know if you have any ideas for me.
thanks,
Toni

Here is an an example using the holiday table combined with the this_year view in the previous example.
SQL> create table holiday (holiday date,
  2    country varchar2(2), description varchar2(30));
Table created.
SQL> insert into holiday values (date '2006-01-23', 'NL',
  2    'National Cheese Day');
1 row created.
SQL> select day, weekend, description holiday,
  2    case when weekend = 'N' and holiday is null then
  3      'Y' else 'N' end business_day
  4  from this_year, holiday
  5  where day between sysdate - 5 and sysdate + 5
  6    and day = holiday (+)
  7  order by day;
DAY       WEEKEND HOLIDAY                        BUSINESS_DAY
19-JAN-06 N                                      Y
20-JAN-06 N                                      Y
21-JAN-06 Y                                      N
22-JAN-06 Y                                      N
23-JAN-06 N       National Cheese Day            N
24-JAN-06 N                                      Y
25-JAN-06 N                                      Y
26-JAN-06 N                                      Y
27-JAN-06 N                                      Y
28-JAN-06 Y                                      N
10 rows selected.
SQL>

Similar Messages

  • SQL Query to calculate on-time dispatch with a calendar table

    Hi Guys,
    I have a query (view) to calculate orders' fulfillment leadtimes.
    The current criteria exclude week-ends but not bank holidays therefore I have created a calendar table with a column name
    isBusinessDay but I don't know how to best use this table to calculate the On-Time metric. I have been looking everywhere but so far I have been unable to solve my problem.
    Please find below the current calculation for the On-Time Column:
    SELECT
    Week#
    , ClntGroup
    , CORD_DocumentCode
    , DESP_DocumentCode
    , Cord_Lines --#lines ordered
    , CORD_Qty --total units orderd
    , DESP_Lines --#lines dispatched
    , DESP_Qty --total units dispatched
    , Status
    , d_status
    , OpenDate --order open date
    , DateDue
    , DESP_PostedDate --order dispatched date
    , DocType
    , [Lead times1]
    , [Lead times2]
    , InFxO
    , OnTime
    , InFxO + OnTime AS InFullAndOneTime
    , SLADue
    FROM (
    SELECT
    DATEPART(WEEK, d.DateOpn) AS Week#
    , Clients.CustCateg
    , Clients.ClntGroup
    , d.DocumentCode AS CORD_DocumentCode
    , CDSPDocs.DocumentCode AS DESP_DocumentCode
    , COUNT(CORDLines.Qnty) AS Cord_Lines
    , SUM(CORDLines.Qnty) AS CORD_Qty
    , COUNT(CDSPLines.Qnty) AS DESP_Lines
    , SUM(CDSPLines.Qnty) AS DESP_Qty
    , CDSPLines.Status
    , d.Status AS d_status
    , d.OpenDate
    , d.DateDue
    , CDSPDocs.PostDate AS DESP_PostedDate
    , d.DocType
    , DATEDIFF(DAY, d.OpenDate, d.DateDue) AS [Lead times1]
    , DATEDIFF(DAY, d.OpenDate, CDSPDocs.PostDate) AS [Lead times2]
    , CASE WHEN SUM(CORDLines.Qnty) = SUM(CDSPLines.Qnty) THEN 1 ELSE 0 END AS InFxO --in-full
    --On-Time by order according to Despatch SLAs
    , CASE
    WHEN Clients.ClntGroup IN ('Local Market', 'Web Sales', 'Mail Order')
    AND (DATEDIFF(DAY, d.OpenDate, CDSPDocs.PostDate) - (DATEDIFF(WEEK, d.OpenDate, CDSPDocs.PostDate) * 2 ) <= 2)
    THEN 1
    WHEN Clients.ClntGroup IN ('Export Market', 'Export Market - USA')
    AND (DATEDIFF(DAY, d.OpenDate, CDSPDocs.PostDate) - (DATEDIFF(WEEK, d.OpenDate, CDSPDocs.PostDate) * 2) <= 14)
    THEN 1
    WHEN Clients.ClntGroup = 'Export Market' OR Clients.CustCateg = 'UK Transfer'
    AND d.DateDue >= CDSPDocs.PostDate
    THEN 1
    ELSE 0
    END AS OnTime
    --SLA Due (as a control)
    , CASE
    WHEN Clients.ClntGroup IN ('Local Market', 'Web Sales','Mail Order') AND CDSPDocs.PostDate is Null
    THEN DATEADD(DAY, 2 , d.OpenDate)
    WHEN Clients.ClntGroup IN ('Export Market', 'Export Market - UK', 'Export Market - USA') OR (Clients.CustCateg = 'UK Transfer')
    AND CDSPDocs.PostDate IS NULL
    THEN DATEADD (DAY, 14 , d.OpenDate)
    ELSE CDSPDocs.PostDate
    END AS SLADue
    FROM dbo.Documents AS d
    INNER JOIN dbo.Clients
    ON d.ObjectID = dbo.Clients.ClntID
    AND Clients.ClientName NOT in ('Samples - Free / Give-aways')
    LEFT OUTER JOIN dbo.DocumentsLines AS CORDLines
    ON d.DocID = CORDLines.DocID
    AND CORDLines.TrnType = 'L'
    LEFT OUTER JOIN dbo.DocumentsLines AS CDSPLines
    ON CORDLines.TranID = CDSPLines.SourceID
    AND CDSPLines.TrnType = 'L'
    AND (CDSPLines.Status = 'Posted' OR CDSPLines.Status = 'Closed')
    LEFT OUTER JOIN dbo.Documents AS CDSPDocs
    ON CDSPLines.DocID = CDSPDocs.DocID
    LEFT OUTER JOIN DimDate
    ON dimdate.[Date] = d.OpenDate
    WHERE
    d.DocType IN ('CASW', 'CORD', 'MORD')
    AND CORDLines.LneType NOT IN ('Fght', 'MANF', 'Stor','PACK', 'EXPS')
    AND CORDLines.LneType IS NOT NULL
    AND d.DateDue <= CONVERT(date, GETDATE(), 101)
    GROUP BY
    d.DateOpn
    ,d.DocumentCode
    ,Clients.CustCateg
    ,CDSPDocs.DocumentCode
    ,d.Status
    ,d.DocType
    ,d.OpenDate
    ,d.DateReq
    ,CDSPDocs.PostDate
    ,CDSPLines.Status
    ,Clients.ClntGroup
    ,d.DocumentName
    ,d.DateDue
    ,d.DateOpn
    ) AS derived_table
    Please find below the DimDate table
    FullDateNZ HolidayNZ IsHolidayNZ IsBusinessDay
    24/12/2014 NULL 0 1
    25/12/2014 Christmas Day 1 0
    26/12/2014 Boxing Day 1 0
    27/12/2014 NULL 0 0
    28/12/2014 NULL 0 0
    29/12/2014 NULL 0 1
    30/12/2014 NULL 0 1
    31/12/2014 NULL 0 1
    1/01/2015 New Year's Day 1 0
    2/01/2015 Day after New Year's 1 0
    3/01/2015 NULL 0 0
    4/01/2015 NULL 0 0
    5/01/2015 NULL 0 1
    6/01/2015 NULL 0 1
    This is what I get from the query:
    Week# ClntGroup CORD_DocumentCode OpenDate DESP_PostedDate OnTime
    52 Web Sales 123456 24/12/2014 29/12/2014 0
    52 Web Sales 123457 24/12/2014 30/12/2014 0
    52 Web Sales 123458 24/12/2014 29/12/2014 0
    52 Local Market 123459 24/12/2014 29/12/2014 0
    1 Web Sale 123460 31/12/2014 5/01/2015 0
    1 Local Market 123461 31/12/2014 6/01/2015 0
    As the difference between the dispatched and open date is 2 business days or less, the result I expect is this:
    Week# ClntGroup CORD_DocumentCode OpenDate DESP_PostedDate OnTime
    52 Web Sales 123456 24/12/2014 29/12/2014 1
    52 Web Sales 123457 24/12/2014 30/12/2014 1
    52 Web Sales 123458 24/12/2014 29/12/2014 1
    52 Local Market 123459 24/12/2014 29/12/2014 1
    1 Web Sale 123460 31/12/2014 5/01/2015 1
    1 Local Market 123461 31/12/2014 6/01/2015 1
    I am using SQL Server 2012
    Thanks
    Eric

    >> The current criteria exclude week-ends but not bank holidays therefore I have created a calendar table with a column name “isBusinessDay” but I don't know how to best use this table to calculate the On-Time metric. <<
    The Julian business day is a good trick. Number the days from whenever your calendar starts and repeat a number for a weekend or company holiday.
    CREATE TABLE Calendar
    (cal__date date NOT NULL PRIMARY KEY, 
     julian_business_nbr INTEGER NOT NULL, 
    INSERT INTO Calendar 
    VALUES ('2007-04-05', 42), 
     ('2007-04-06', 43), -- good Friday 
     ('2007-04-07', 43), 
     ('2007-04-08', 43), -- Easter Sunday 
     ('2007-04-09', 44), 
     ('2007-04-10', 45); --Tuesday
    To compute the business days from Thursday of this week to next
     Tuesdays:
    SELECT (C2.julian_business_nbr - C1.julian_business_nbr)
     FROM Calendar AS C1, Calendar AS C2
     WHERE C1.cal__date = '2007-04-05',
     AND C2.cal__date = '2007-04-10'; 
    We do not use flags in SQL; that was assembly language. I see from your code that you are still in a 1960's mindset. You used camelCase for a column name! It makes the eyes jump and screws up maintaining code; read the literature. 
    The “#” is illegal in ANSI/ISO Standard SQL and most other ISO Standards. You are writing 1970's Sybase dialect SQL! The rest of the code is a mess. 
    The one column per line, flush left and leading comma layout tells me you used punch cards when you were learning programming; me too! We did wrote that crap because a card had only 80 columns and uppercase only IBM 027 character sets. STOP IT, it make you
    look stupid in 2015. 
    You should follow ISO-11179 rules for naming data elements. You failed. You believe that “status” is a precise, context independent data element name! NO! 
    You should follow ISO-8601 rules for displaying temporal data. But you used a horrible local dialect. WHY?? The “yyyy-mm-dd” is the only format in ANSI/ISO Standard SQL. And it is one of the most common standards embedded in ISO standards. Then you used crap
    like “6/01/2015” which is varying length and ambiguous that might be “2015-06-01” or “2015-01-06” as well as not using dashes. 
    We need to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. 
    And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> Please find below the current calculation for the On-Time Column: <<
    “No matter how far you have gone down the wrong road, turn around”
     -- Turkish proverb
    Can you throw out this mess and start over? If you do not, then be ready to have performance got to hell? You will have no maintainable code that has to be kludged like you are doing now? In a good schema an OUTER JOIN is rare, but you have more of them in
    ONE statement than I have seen in entire major corporation databases.
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Creating Fiscal/Calendar Table

    Hello,
    Please, help to create a Fiscal and Calendar table with the following conditions:
    The table and the first fiscal year start from 01/31/2011
    The end date could be 12/31/2020 (not that important as it could be a smaller date)
    All the next fiscal years should start 52 weeks after on the following Monday.
    I’m trying to modify the following code that is calculating the beginning of the fiscal year with 52 weeks ahead but with following Monday only for the first next Fiscal Year.
    Thanks
    DECLARE
    @StartDate smalldatetime
    = '01/31/2011'
    --First Calendar date to include in table
    DECLARE
    @EndDate smalldatetime
    = '12/31/2020'
    --Last calendar date to include in the table
    declare
    @FiscalYearBegin_First smalldatetime
    = '1/31/2011'
    DECLARE
    @Cycle INT
    = 52
    SET
    DATEFIRST 7
     ;WITH
    --This secton generates the number table
    E00(N)
    AS (SELECT 1
    UNION ALL
    SELECT 1),
    E02(N)
    AS (SELECT 1
    FROM E00
    a, E00
    b),
    E04(N)
    AS (SELECT 1
    FROM E02
    a, E02
    b),
    E08(N)
    AS (SELECT 1
    FROM E04
    a, E04
    b),
    E16(N)
    AS (SELECT 1
    FROM E08
    a, E08
    b),
    E32(N)
    AS (SELECT 1
    FROM E16
    a, E16
    b),
    cteTally(N)
    AS (SELECT
    ROW_NUMBER()
    OVER (ORDER
    BY N)
    FROM E32),
    --This CTE generates a list of calendar dates
    CalendarBase
    as (
     SELECT
    DateKey =
    n
    , CalendarDate
    = DATEADD(day,
    n -1,
    @StartDate )
    case when n
    = 1 then
    @FiscalYearBegin_First 
    else
    case when
    datepart(dw,DATEADD(DAY,
    n -1
    , @StartDate ))
    = 2 then 
    dateadd(week,CAST(ABS(DATEDIFF(WEEK,DATEADD(day,
    n -1
    , @StartDate ),@StartDate))/@Cycle
    AS INT)
    * @Cycle,@FiscalYearBegin_First)
    else
    dateadd(week,
    datediff(week, 0,
    dateadd(week,CAST(ABS(DATEDIFF(WEEK,DATEADD(day,
    n - 1,
    @StartDate ),@StartDate))/@Cycle
    AS INT)
    * @Cycle,@FiscalYearBegin_First)), 7)
    end
    end FiscalYearBegin
    FROM cteTally
      WHERE
    N <=
    DATEDIFF(day,
    @StartDate ,
    @EndDate +1)
    --Finally, use the list of calendar dates to fill the date dimension
    SELECT
    DateKey
    , IsoDate      
    = CONVERT(char(8),
    CalendarDate, 112)
    , CalendarDate
    , CalendarYear 
    = YEAR(CalendarDate)
    , CalendarQuarter
    =  (DATEPART(QUARTER,CalendarDate)
    , CalendarMonth
    = MONTH(CalendarDate)
    , CalendarDay  
    = DATEPART(DAY,
    CalendarDate)
    , DayofWk      
    = DATEPART(Dw,
    CalendarDate)
    , CalendarWeekOfMonth
    = DATEDIFF(week,
    DATEADD(day,1,
    CalendarDate-DAY(CalendarDate)
    + 1)
    -1, CalendarDate)
    +1
    , WeekofYr     
    = DATEPART(WEEK,
    CalendarDate)
    , DayofYr      
    = DATEPART(DAYOFYEAR,
    CalendarDate)
    , NameMonth    
    = DATENAME(Month,
    CalendarDate)
    , NameDay      
    = DATENAME
    (Weekday,CalendarDate
    , FiscalYear   
    = YEAR(FiscalYearBegin)
    , FiscalMonth   
    = DATEDIFF(
    MONTH,
    FiscalYearBegin,
    CalendarDate) + 1
    , FiscalQuarter  
    = DATEDIFF(
    QUARTER,
    FiscalYearBegin,
    CalendarDate) + 1
    , FiscalWeek    
    = DATEDIFF(
    WEEK,
    FiscalYearBegin,
    CalendarDate) + 1
    , FiscalDay     
    = DATEDIFF(
    day,
    FiscalYearBegin,
    CalendarDate) + 1
    FROM
    CalendarBase

    Try the below code if this meets your requirement.
    DECLARE @StartDate DATETIME = '01-31-2011'
    ,@EndDate DATETIME = '12-31-2020'
    ;WITH cteCalendar (CurrentDate,WeekDay,DayNum,WeekNum)
    AS
    (SELECT @StartDate AS CurrentDate, DATENAME(WEEKDAY,@StartDate) AS WeekDay, 1 AS MonthCode, 1 AS WeekNum
    UNION ALL
    SELECT DATEADD(DD,1,cte.CurrentDate) AS CurrentDate, DATENAME(WEEKDAY,DATEADD(DD,1,cte.CurrentDate)) AS WeekDay, cte.DayNum + 1 AS DayNum
    , cte.DayNum / 7 + 1 as WeekNum
    FROM cteCalendar cte
    WHERE cte.CurrentDate + 1 <= @EndDate
    SELECT CurrentDate,WeekDay
    ,CASE WHEN WeekNum%52 = 0 THEN 52
    ELSE WeekNum%52 END AS WeekNumber
    ,DATEPART(YY,@StartDate) + (WeekNum - 1)/52 AS FiscalYear
    FROM cteCalendar
    OPTION (MAXRECURSION 0)
    Only year condition was mentioned and you didn't mention about month, so i did not consider month in the result set. If month is also required, share the condition (30Days in a month or 4Weeks in month?)
    Let me know if i got you wrong.

  • Calendar Table Population

    Hi
    I need to populate a calendar table with two fields date(for 10 yrs) and Holiday Flag.Holiday flag will be Y if its saturday and Sunday and N for weekdays.
    Can anyone please provide me with the script to populate the table.
    Thanks

    Hi Jameel,
    Well, when I said version dependant, the result can differ :
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.7.0 - Production
    SQL> select sysdate+rownum,
      2  decode(to_char(sysdate+rownum,'Dy'),'Sat','Y','Sun','Y','N')
      3  from dual connect by level<=10;
    SYSDATE+ D
    11/06/06 Y
    =================================================
      1  select sysdate+rownum,
      2  decode(to_char(sysdate+rownum,'Dy'),'Sat','Y','Sun','Y','N')
      3* from dual connect by level<=10
    SCOTT@demo102> /
    SYSDATE+ D
    11/06/06 Y
    12/06/06 N
    13/06/06 N
    14/06/06 N
    15/06/06 N
    16/06/06 N
    17/06/06 Y
    18/06/06 Y
    19/06/06 N
    20/06/06 N
    10 rows selected.
    SCOTT@demo102> select * from v$version where rownum=1;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod
    SCOTT@demo102> Without said about 10.1.0.2 (which I don't have) which give 11 rows with the same query above (see Re: Cube Function
    All these facts said me that we have to use others ways like pipelined (as showed the link I gave above) or dimension...
    Nicolas.

  • Split date range without Calendar table

    Hi guys!
    Is there any way to split date ranges (to days / hours / minutes) in one table without using Calendar table (without joining 2 tables)?
    Reason I'm asking this is because we have a huge Fact table (500+ million records) and joining small Calendar table and this huge Fact table takes considerable amount of time.
    So far we tried:
    Join 2 tables (Fact and Calendar)
    Cross Applying Calendar and table-valued function (that returns necessary measures from Fact table)
    and both approaches took few minutes for 1 day to complete.
    Most successful test we had so far was using CLR and executing table-valued functions in parallel for different 15 minute periods. This way we were able to get the results in 3-4 seconds.
    Anyway, is there any effective pure T-SQL way to accomplish this?
    Thanks in advance,
    Miljan

    Try using a temporary table rather than table variable.. You can have a CI on the date column.
    or
    declare @PeriodStart datetime2(0) = '2013-01-05 00:00:00'
    declare @PeriodEnd datetime2(0) = '2013-01-05 02:00:00'
    select T.PeriodStart, T.PeriodEnd, count(Column1)as count1, sum(Column2)as sum1
    from Fact F with(nolock)WHERE F.[Start]>= '19000101' AND <=@PeriodStartand F.[End] >= @PeriodEnd and F.[End] <='20200101'
    group by T.PeriodStart, T.PeriodEnd
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • MTD,YTD,PTD without calendar table

              QTY
          Month
          Year
    QTY_YTD
    QTY_MTD
    QTY_PTD
    10
    1
    2010
    20
    2
    2010
    20
    1
    2012
    30
    3
    2012
    Above is how my table looks like and  all are having integer datatypes
    I dont have a calendar table to join hence without calendar table can I compute YTD,MTD,PTD?
    If so what will be the case queries
    Mudassar

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
    The report period table gives a name to a range of dates that is common to the entire enterprise. 
    CREATE TABLE Something_Report_Periods
    (something_report_name CHAR(10) NOT NULL PRIMARY KEY
       CHECK (something_report_name LIKE <pattern>),
     something_report_start_date DATE NOT NULL,
     something_report_end_date DATE NOT NULL,
      CONSTRAINT date_ordering
        CHECK (something_report_start_date <= something_report_end_date),
    etc);
    These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
    data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Date & Calendar table

    Hi
    I have a table with entries that have a date attribute i want to know which dates were not entered for a specific period
    Is there a predefined calendar table?
    Thanks

    Here's an example of the sort of thing you can do...
    SQL> ed
    Wrote file afiedt.buf
      1  with cal as (select min_hiredate+rn-1 as dt
      2               from (select min(hiredate) min_hiredate from emp2), (select rownum rn from dual
      3                                                       connect by rownum <= (select max(hiredate)-min(hiredate)+1 from emp2))
      4              )
      5  -- end of calendar
      6  select cal.dt as cal_date
      7        ,emp2.*
      8  from cal left outer join emp2 on (cal.dt = emp2.hiredate)
      9* order by 1
    SQL> /
    CAL_DATE         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO
    23-JAN-2008       7934 MILLER     CLERK           7782 23-JAN-2008       1300                    10
    24-JAN-2008
    25-JAN-2008
    26-JAN-2008
    27-JAN-2008
    28-JAN-2008
    29-JAN-2008
    30-JAN-2008
    31-JAN-2008
    01-FEB-2008
    02-FEB-2008
    03-FEB-2008
    04-FEB-2008
    05-FEB-2008
    06-FEB-2008
    07-FEB-2008
    08-FEB-2008
    09-FEB-2008
    10-FEB-2008
    11-FEB-2008
    12-FEB-2008
    13-FEB-2008
    14-FEB-2008
    15-FEB-2008
    16-FEB-2008
    17-FEB-2008
    18-FEB-2008
    19-FEB-2008
    20-FEB-2008       7499 ALLEN      SALESMAN        7698 20-FEB-2008       1600        300         30
    21-FEB-2008
    22-FEB-2008       7521 WARD       SALESMAN        7698 22-FEB-2008       1250        500         30
    23-FEB-2008
    24-FEB-2008
    25-FEB-2008
    26-FEB-2008
    27-FEB-2008
    28-FEB-2008
    29-FEB-2008
    01-MAR-2008
    02-MAR-2008
    03-MAR-2008
    04-MAR-2008
    05-MAR-2008
    06-MAR-2008
    07-MAR-2008
    08-MAR-2008
    09-MAR-2008
    10-MAR-2008
    11-MAR-2008
    12-MAR-2008
    13-MAR-2008
    14-MAR-2008
    15-MAR-2008
    16-MAR-2008
    17-MAR-2008
    18-MAR-2008
    19-MAR-2008
    20-MAR-2008
    21-MAR-2008
    22-MAR-2008
    23-MAR-2008
    24-MAR-2008
    25-MAR-2008
    26-MAR-2008
    27-MAR-2008
    28-MAR-2008
    29-MAR-2008
    30-MAR-2008
    31-MAR-2008
    01-APR-2008
    02-APR-2008       7566 JONES      MANAGER         7839 02-APR-2008       2975                    20
    03-APR-2008
    04-APR-2008
    05-APR-2008
    06-APR-2008
    07-APR-2008
    08-APR-2008
    09-APR-2008
    10-APR-2008
    11-APR-2008
    12-APR-2008
    13-APR-2008
    14-APR-2008
    15-APR-2008
    16-APR-2008
    17-APR-2008
    18-APR-2008
    19-APR-2008       7788 SCOTT      ANALYST         7566 19-APR-2008       3000                    20
    20-APR-2008
    21-APR-2008
    22-APR-2008
    23-APR-2008
    24-APR-2008
    25-APR-2008
    26-APR-2008
    27-APR-2008
    28-APR-2008
    29-APR-2008
    30-APR-2008
    01-MAY-2008       7698 BLAKE      MANAGER         7839 01-MAY-2008       2850                    30
    02-MAY-2008
    03-MAY-2008
    04-MAY-2008
    05-MAY-2008
    06-MAY-2008
    07-MAY-2008
    08-MAY-2008
    09-MAY-2008
    10-MAY-2008
    11-MAY-2008
    12-MAY-2008
    13-MAY-2008
    14-MAY-2008
    15-MAY-2008
    16-MAY-2008
    17-MAY-2008
    18-MAY-2008
    19-MAY-2008
    20-MAY-2008
    21-MAY-2008
    22-MAY-2008
    23-MAY-2008       7876 ADAMS      CLERK           7788 23-MAY-2008       1100                    20
    24-MAY-2008
    25-MAY-2008
    26-MAY-2008
    27-MAY-2008
    28-MAY-2008
    29-MAY-2008
    30-MAY-2008
    31-MAY-2008
    01-JUN-2008
    02-JUN-2008
    03-JUN-2008
    04-JUN-2008
    05-JUN-2008
    06-JUN-2008
    07-JUN-2008
    08-JUN-2008
    09-JUN-2008       7782 CLARK      MANAGER         7839 09-JUN-2008       2450                    10
    10-JUN-2008
    11-JUN-2008
    12-JUN-2008
    13-JUN-2008
    14-JUN-2008
    15-JUN-2008
    16-JUN-2008
    17-JUN-2008
    18-JUN-2008
    19-JUN-2008
    20-JUN-2008
    21-JUN-2008
    22-JUN-2008
    23-JUN-2008
    24-JUN-2008
    25-JUN-2008
    26-JUN-2008
    27-JUN-2008
    28-JUN-2008
    29-JUN-2008
    30-JUN-2008
    01-JUL-2008
    02-JUL-2008
    03-JUL-2008
    04-JUL-2008
    05-JUL-2008
    06-JUL-2008
    07-JUL-2008
    08-JUL-2008
    09-JUL-2008
    10-JUL-2008
    11-JUL-2008
    12-JUL-2008
    13-JUL-2008
    14-JUL-2008
    15-JUL-2008
    16-JUL-2008
    17-JUL-2008
    18-JUL-2008
    19-JUL-2008
    20-JUL-2008
    21-JUL-2008
    22-JUL-2008
    23-JUL-2008
    24-JUL-2008
    25-JUL-2008
    26-JUL-2008
    27-JUL-2008
    28-JUL-2008
    29-JUL-2008
    30-JUL-2008
    31-JUL-2008
    01-AUG-2008
    02-AUG-2008
    03-AUG-2008
    04-AUG-2008
    05-AUG-2008
    06-AUG-2008
    07-AUG-2008
    08-AUG-2008
    09-AUG-2008
    10-AUG-2008
    11-AUG-2008
    12-AUG-2008
    13-AUG-2008
    14-AUG-2008
    15-AUG-2008
    16-AUG-2008
    17-AUG-2008
    18-AUG-2008
    19-AUG-2008
    20-AUG-2008
    21-AUG-2008
    22-AUG-2008
    23-AUG-2008
    24-AUG-2008
    25-AUG-2008
    26-AUG-2008
    27-AUG-2008
    28-AUG-2008
    29-AUG-2008
    30-AUG-2008
    31-AUG-2008
    01-SEP-2008
    02-SEP-2008
    03-SEP-2008
    04-SEP-2008
    05-SEP-2008
    06-SEP-2008
    07-SEP-2008
    08-SEP-2008       7844 TURNER     SALESMAN        7698 08-SEP-2008       1500          0         30
    09-SEP-2008
    10-SEP-2008
    11-SEP-2008
    12-SEP-2008
    13-SEP-2008
    14-SEP-2008
    15-SEP-2008
    16-SEP-2008
    17-SEP-2008
    18-SEP-2008
    19-SEP-2008
    20-SEP-2008
    21-SEP-2008
    22-SEP-2008
    23-SEP-2008
    24-SEP-2008
    25-SEP-2008
    26-SEP-2008
    27-SEP-2008
    28-SEP-2008       7654 MARTIN     SALESMAN        7698 28-SEP-2008       1250       1400         30
    29-SEP-2008
    30-SEP-2008
    01-OCT-2008
    02-OCT-2008
    03-OCT-2008
    04-OCT-2008
    05-OCT-2008
    06-OCT-2008
    07-OCT-2008
    08-OCT-2008
    09-OCT-2008
    10-OCT-2008
    11-OCT-2008
    12-OCT-2008
    13-OCT-2008
    14-OCT-2008
    15-OCT-2008
    16-OCT-2008
    17-OCT-2008
    18-OCT-2008
    19-OCT-2008
    20-OCT-2008
    21-OCT-2008
    22-OCT-2008
    23-OCT-2008
    24-OCT-2008
    25-OCT-2008
    26-OCT-2008
    27-OCT-2008
    28-OCT-2008
    29-OCT-2008
    30-OCT-2008
    31-OCT-2008
    01-NOV-2008
    02-NOV-2008
    03-NOV-2008
    04-NOV-2008
    05-NOV-2008
    06-NOV-2008
    07-NOV-2008
    08-NOV-2008
    09-NOV-2008
    10-NOV-2008
    11-NOV-2008
    12-NOV-2008
    13-NOV-2008
    14-NOV-2008
    15-NOV-2008
    16-NOV-2008
    17-NOV-2008       7839 KING       PRESIDENT            17-NOV-2008       5000                    10
    18-NOV-2008
    19-NOV-2008
    20-NOV-2008
    21-NOV-2008
    22-NOV-2008
    23-NOV-2008
    24-NOV-2008
    25-NOV-2008
    26-NOV-2008
    27-NOV-2008
    28-NOV-2008
    29-NOV-2008
    30-NOV-2008
    01-DEC-2008
    02-DEC-2008
    03-DEC-2008       7900 JAMES      CLERK           7698 03-DEC-2008        950                    30
    03-DEC-2008       7902 FORD       ANALYST         7566 03-DEC-2008       3000                    20
    04-DEC-2008
    05-DEC-2008
    06-DEC-2008
    07-DEC-2008
    08-DEC-2008
    09-DEC-2008
    10-DEC-2008
    11-DEC-2008
    12-DEC-2008
    13-DEC-2008
    14-DEC-2008
    15-DEC-2008
    16-DEC-2008
    17-DEC-2008       7369 SMITH      CLERK           7902 17-DEC-2008        800                    20
    331 rows selected.
    SQL>

  • Factory calendar table update

    Hello gurus,
    An urgent requirement!!!
    I have three Source system configured in BW.
    The FActory cal id for the two systems were not found in BW.
    When i use rebuild table for the factory calendar id using transfer global setting option in the source system it updates the table but over writes it when i use the same option for other source system.
    Suggestion please
    Thanks in advance
    Ram

    Hi,
    the program doesn't admit the update on factory calendar!!
    You need an alternative way.
    I suggest two possibility:
    Transaction SCU0 to compare all the tables by RFC in remote system, (you can automate this comparison in a program) But the comparing will be for all tables:
    TCALS
    TFACD
    TFACS
    TFACT
    TFAIN
    TFAIT
    THOC
    THOCD
    THOCI
    THOCS
    THOCT
    THOL
    THOLT
    THOLU
    or for the IMG activity related to calendar.
    Other way is to use the BC set functionality. When you make modification in a calendar in source system you insert all modifications in a request, then you can get this request in a BC set. After you can download it and upload in BW.
    Regards,
    Sergio

  • Holiday calendar table logic required in sql instead of pl sql

    My function fn_test calculates the date-1. And if it's a holiday according to the table temp_calendar, then it recursively calls the fn_test again to do -1. This happens till I get a non holiday date.
    I have implemented as follows:
    But can I have a single SQL do it which is more efficient?
    Drop table temp_calendar;
    Create table temp_calendar(
    id number,
    holiday date);
    Insert into temp_calendar values (1, '5-Jan-2012');
    Insert into temp_calendar values (1, '6-Jan-2012');
    Insert into temp_calendar values (1, '10-Jan-2012');
    Insert into temp_calendar values (1, '2-Feb-2012');
    Insert into temp_calendar values (1, '11-Feb-2012');
    Commit;
    CREATE OR REPLACE FUNCTION fn_test (in_date IN DATE)
    RETURN DATE
    IS
    v_pr_day DATE;
    BEGIN
    v_pr_day := in_date-1;
    FOR Calendar_Dates IN (SELECT holiday FROM temp_calendar)
    LOOP
    IF (v_pr_day = Calendar_Dates.holiday)
    THEN
    v_pr_day := fn_test (v_pr_day);
    END IF;
    END LOOP;
    RETURN TRUNC (v_pr_day);
    END fn_test;
    Select fn_test('8-JAN-2012') from dual; -- Returns 7 Jan as no holiday in table temp_calendar.
    But Select fn_test('7-JAN-2012') from dual; --Returns 4 Jan as 6 and 5 are holidays in table temp_calendar.
    Thanks..

    If you really want pure SQL Solution, foolproof, without recursion, this will work
    SELECT MIN (last_working_day)
    FROM   (SELECT period_start - 1 last_working_day
            FROM   (SELECT   MIN (holiday) period_start, MAX (holiday) period_end
                    FROM     (SELECT holiday, MAX (contig) OVER (ORDER BY holiday) contiguous_group
                              FROM   (SELECT holiday,
                                             LAG (holiday) OVER (ORDER BY holiday),
                                             ROW_NUMBER () OVER (ORDER BY holiday),
                                             CASE
                                                WHEN LAG (holiday) OVER (ORDER BY holiday) != holiday - 1
                                      OR              ROW_NUMBER () OVER (ORDER BY holiday) = 1 THEN ROW_NUMBER () OVER (ORDER BY holiday)
                                                ELSE NULL
                                             END
                                                contig
                                      FROM   temp_calendar))
                    GROUP BY contiguous_group) holiday_range
            WHERE  :input_date - 1 BETWEEN period_start AND period_end
            UNION ALL
            SELECT :input_date - 1 last_working_day FROM DUAL)This will overcome the limitation of 30 days posted by Jeneesh

  • Tables for Factory Calendar

    Hello
    I am looking for the schema of the connections / relationships between the calendar tables:
    TFACD     Factory calendar definition
    TFACS     Factory calendar (display)
    TFACT     Factory calendar texts
    TFAIN     Calendar: Intervals for company holidays, special shifts
    TFAIT     Calendar: Text for factory calendar intervals
    THOC     Public Holiday Calendar
    THOCD     Public holiday definitions
    THOL     Public Holidays
    THOLT     Public holiday text
    and more, if more exist....
    Do you have any documentation, how these tables relates each other? WHat actually they contain?
    Thanks in advance,
    Kooyot

    Hello Kooyot,
    in ta. SE11 there is a button "Graphic" (or use key combination Ctrl.ShiftF11), where you can display all relevant table relationships. You can do this in this dialog by clicking on the buttons "Ing.", "Outg.", "Check Tables" and "Foreign key tables", probably you have to change the focus in the "Display Area" to reach all dependent relationships, which you can see in detail by clicking on the edges between the tables.
    Hope this helps,
    regards Martin

  • Advice needed on designing schema to accomodate multiple transaction tables.

    Hi,
    The attached images shows my current schema. It consists of three transaction tables, a product table and a calendar table.
    - Background -
    The product table 'Q1 Data Set' contains all unique sales. In addition it also contains a number of columns by which I will later filter my pivot tables (e.g. whether the customer of the order is new/returning). This
    table also contains a column named 'DateOrdered',the date the order was originally placed (but not paid). 
    Each sale that is paid can be done so either in a single transaction, or across multiple transactions of different transaction types.
    An example of a sale  paid in multiple parts would be an order that has three transactions;
    one online (table 'trans_sagepay',
    one over the phone (table'trans_epdq')
    and another by card (table'trans_manual'). Furthermore there can be more than one transaction of each type for an sale.
    I have created measures which total the sales in each transaction table.
    Each transaction has a 'transaction_date' which is the date of that individual transaction.
    The calendar is simply a date table that has some friendly formatted columns for laying out pivot tables. An example column
    is FiscalMonthAbbrv which displays months similar to '(04) - January'
    to accommodate our fiscal year.
    - Problem -
    My problem is that I need the ability to create some tables that have the
    Date Ordered as the rows (listed by Year>Month), and I need to produce other tables that have
    Transaction Date as the rows.  
    Date ordered works fine, however the problem comes when I try and create a table based on the transaction date.
    With the current model seen in the attached image I cannot do it because the transactions have a relationship to
    Q1 Data Set and this table has the relationship with the
    Cal_Trans table. What happens in this scenario is that whenever I set the rows to be FiscalMonthAbbr  the values it displays is the transactions based not on transaction date but date ordered. To explain further:
    If I have an order A with a DateOrdered of 01/01/2014, but the transaction of £100 for that order was made later on the 05/01/2014, that £100 is incorrectly attributed to the 01/01/2014.
    To clarify the type of table I am aiming for see the mock-up below, I however NEED the ability to filter this table using columns found in
    Q1 Data Set.
    How can I make a schema so that I can use both DateOrdered and TransactionDate? I cannot combine all three transaction tables into one because each transaction type has columns unique to that specific type.

    Thanks for your suggestions, at the moment I don't have time to prepare a non-confidential copy of the data model, however I've taken one step forward, and one step back!
    First to clarify; to calculate sales of each transaction type I have created the following measures (I've given them friendly names):
    rev_cash
    rev_online
    rev_phone
    I then have a measure called rev_total which sums together the above measures. This allows me to calculate total revenue, but also to break it down by transaction type.
    With this in mind I revised the schema based on Visakh original suggestion to look like this:
    Using this I was able to produce a table which looked like that below:
    There were two issues with this:
    If I add the individual measures for each transaction type I get no errors, as soon as I add the 'Total Sales' measure on the end of the table I get an error "Relationship between tables may be needed". Seemingly however the numbers still calculate as expected
    - what is causing this error and how do I remove it?
    I CAN with this scenario filter by 'phd' which is a column in the Q1 Data Set table
    and it works as expected. I cannot however filter by all columns in this table, an example would be 'word count'.
    'Word Count' is a integer column, each record in the Q1 Data Set table has a value set for this column.
    I would like to take the column above and add a new measure called 'Total Word Count' (which I have created) which will calculate the total number of words in that monthly period. When I add this however I get the same relationship error as above and it
    display the word count total for the entire source tbale for every row of the pivot table.
    How can I get this schema working so that I can filter by word count and other columns from the product table. It Is confusing me how I can filter by one column, but not by a another in the same table.
    Also, I don't fully understand how I would add a second date table or how it would help my issues.
    Thanks very much for you help.

  • How can I create a new calendar that starts the week on monday?

    Excel can do it, but I really like the template for calendars in numbers. That calendar is for printing it, so i don't need any special functionalities, only the template, with blank cells i can hand-write in.
    Thanks!

    Hi And95es,
    The Calendar template is very clever. Changing it to start on Monday would be a huge task. Here is an idea for a non-automatic calendar. Start with a table for month and year. Hide the table name if you like.
    A1 is a pop-up menu to choose a month. Type the year in B1.  I am trying to come up with a formula to show the day of the week for that month and year in B2. This is because you will have to type a 1 into the correct day in the calendar table to generate dates for the whole month.
    Create an  outline calendar like this:
    A2 contains the number 1
    B2=A2+1 and fill right
    A4=G2+1
    B4=A4+1 and Fill Right.
    Now select Row 4 and copy.
    Paste into every second row below.
    Format the table to make cells big enough to write in. Save as Template because you are about to make a calendar and you will need the template for next month.
    Type a 1 into the cell that is the first of that month. Now clear contents of cells you don't need.
    It would be handy to have a formula to show weekday for the first of the month. Not essential!
    Regards,
    Ian.

  • Calendar not working...

    I have a following piece of code embedded in jsp but its not popping out a calendar...help plz
    <li><label for="flightDepartureDate">Departing:</label> <input
              type="text" name="criteria.displayDepartureDatetime" readonly="readonly"
              onblur="updateCheckout();return true;"
              value="<c:out value="${flightSearchForm.criteria.displayDepartureDatetime}"/>"><a
              href="#showCalendar"
              onClick="displayCalendar('criteria.displayDepartureDatetime', 'false','<%= request.getContextPath() %>');">
         <img src="<cms:ref path="global" reference="images_calendar"/>"
              alt="calendar" title="calendar" /> </a> <label for="flightReturnDate">Returning:</label>
         <input type="text" NAME="criteria.displayReturnDatetime"
              onblur="updateCheckout();return true;"
              value="<c:out value="${flightSearchForm.criteria.displayReturnDatetime}"/>"><a
              href="#showCalendar"
              onClick="displayCalendar('criteria.displayReturnDatetime', 'false','<%= request.getContextPath() %>');"></li>
         <img src="<cms:ref path="global" reference="images_calendar"/>"
              alt="calendar" title="calendar" />
         </a>
         </li>
    // Calendar Library
    // This calendar is used when a user clicks on a link (image or text). A pop-up window is
    // displayed and the user can click on an arrow to move to the next or previous month.
    // When the user clicks on one of the days in the month the calendar window is closed and
    // the selected date will now be displayed in the day and month option lists (focus is
    // returned to the month option list).
    // Usage: Add the following lines of code to your page to enable the Calendar
    // component.
    // // This line loads the JavaScript library for the calendar
    // <script language="JavaScript" src="calendar.js"></script>
    // // This line is used in conjunction with one form field (dateField).
    // // *** NOTE ***
    // <a href="#showCalendar
    // onClick="setDateField(setDateField(document.mainForm.startDate));
    // newWin = window.open('calendar.html','cal','dependent=yes,width=200,height=200')">
    // <img src="../icons/icon_more.png" width=22 height=15 border=0></a>
    // Note : when the calling window is an included jsp page make sure
    // you use top.newWin ! Example Useage in the call centre app is :
    // <a href="#showCalendar
    // onClick="showCalendar('checkOutDate');
    // top.newWin = window.open('<%= request.getContextPath() %>/webcontent/calendar.jsp',
    // 'cal',
    // 'dependent=yes,width=200,height=200, left=500,top=500');">
    // <img src="<cms:ref path="search" reference="images_calendar"/>" alt="calendar" title="calendar" />
    // </a>
    // Required Files:
    // calendar.js - contains all JavaScript functions to make the calendar work
    // calendar.jsp - is the actual calendar that is opened by the initial page when
    // the user clicks on icon_more.gif.
    // image file - image that the user clicks on to view the calendar
    // Begin user editable section ----------------------------------------------------------------------------------------
    // CALENDAR COLORS
    bottomBackground = "#3D70D6"; // BG COLOR OF THE BORDER OUTSIDE CALENDAR TABLE
    tableBGColor = "#dfefff"; // BG COLOR OF THE CALENDAR TABLE
    cellColor = "#ffffff"; // TABLE CELL BG COLOR OF THE DATE CELLS
    headingCellColor = "#3d70d6"; // TABLE CELL BG COLOR OF THE WEEKDAY ABBREVIATIONS
    focusColor = "#ff0000"; // TEXT COLOR OF THE DATE IN THE OPTION LIST (OR CURRENT DATE IF NONE SELECTED)
    hoverColor = "#dfefff"; // TEXT COLOR OF A LINK WHEN YOU HOVER OVER IT
    fontStyle = "8pt arial, helvetica"; // TEXT STYLE FOR DATES
    headingFontStyle = "bold 8pt arial, helvetica"; // TEXT STYLE FOR WEEKDAY ABBREVIATIONS
    // Formatting preferences
    bottomBorder = false; // TRUE/FALSE (WHETHER TO DISPLAY BOTTOM CALENDAR BORDER)
    tableBorder = 0; // SIZE OF CALENDAR TABLE BORDER (BOTTOM FRAME) 0=none
    // End of User Editable Section ---------------------------------------------------------------------------------------
    // Determine browser type
    var isNav = false;
    var isIE = false;
    // Assume Netscape or IE
    if (navigator.appName == "Netscape") {
         isNav = true;
    } else {
         isIE = true;
    var dateField = null;
    var startDay;
    var startMonth;
    var startYear;
    var format = null;
    //used to determine if age needs to be calculated as well
    var updateAge = false;
    // Pre-build portions of the calendar when this JavaScript Library loads into the browser
    buildCalParts();
    // Calendar functions begin here --------------------------------------------------------------------------------------
    Sets the initial value of the global date field
    function showCalendar(inDateField, calcAge) {
         dateField = document.getElementById(inDateField);
    // Set the colours of the calendar
         setCalColour();
         buildCalParts();
    // Set default value of noDateSelected
         noDateSelected = 1;
         setInitialDate();
    //determine if the calculateAge function on the parent must be called;
         updateAge = calcAge;
    // Construct the calendar
         calDocBottom = buildBottomCalFrame();
    function displayCalendar(inDateField, calcAge, calendarPath)
         // lets close the calendar window if its already open. Its safer dude!
         if (top.newWin != null) top.newWin.close();
         calendarURL = calendarPath + "/webcontent/common/calendar.html";
         showCalendar(inDateField, calcAge);
         top.newWin = window.open(calendarURL, "cal", "dependent=yes,width=200,height=200, left=500,top=500");
         top.newWin.focus();
    Set the initial calendar date to today or to the existing value in dateField
    function setInitialDate() {
         calDate = new Date();
         today = new Date();
         currentDate = new Date();
         if (dateField.value.length == 11) {
              noDateSelected = 0;
              var day = dateField.value.substring(0, 2);
              var month = dateField.value.substring(3, 6).toUpperCase();
              var year = dateField.value.substring(7, 11);
              calDate.setYear(year);
              calDate.setDate(1);
              if (month == "JAN") {
                   calDate.setMonth(0);
              } else {
                   if (month == "FEB") {
                        calDate.setMonth(1);
                   } else {
                        if (month == "MAR") {
                             calDate.setMonth(2);
                        } else {
                             if (month == "APR") {
                                  calDate.setMonth(3);
                             } else {
                                  if (month == "MAY") {
                                       calDate.setMonth(4);
                                  } else {
                                       if (month == "JUN") {
                                            calDate.setMonth(5);
                                       } else {
                                            if (month == "JUL") {
                                                 calDate.setMonth(6);
                                            } else {
                                                 if (month == "AUG") {
                                                      calDate.setMonth(7);
                                                 } else {
                                                      if (month == "SEP") {
                                                           calDate.setMonth(8);
                                                      } else {
                                                           if (month == "OCT") {
                                                                calDate.setMonth(9);
                                                           } else {
                                                                if (month == "NOV") {
                                                                     calDate.setMonth(10);
                                                                } else {
                                                                     if (month == "DEC") {
                                                                          calDate.setMonth(11);
                                                                     } else {
                                                                          calDate.setMonth("N/A");
              calDate.setDate(day);
    // IF THE INCOMING DATE IS INVALID, USE THE CURRENT DATE
         if (isNaN(calDate)) {
              noDateSelected = 1;
              calDate = new Date();
         } else {
              startDay = calDate.getDate();
              startMonth = calDate.getMonth();
              startYear = calDate.getYear();
         calDay = calDate.getDate();
         calMonth = calDate.getMonth();
    // Set day value to 1... to avoid JavaScript date calculation anomalies
    // (if the month changes to Feb and the day is 30, the month would change to
    // March and the day would change to 2. Setting the day to 1 will prevent that)
         calDate.setDate(1);
    Sets the calendar colours
    function setCalColour() {
         bottomBackground = "#6598fe";
         tableBGColor = "#dfefff";
         cellColor = "#ffffff";
         hoverColor = "#dfefff";
         logo = "cal_logo_lilac.gif";
    Create the calendar
    function buildBottomCalFrame() {
    // Start calendar document
         var calDoc = calendarBegin + "<div class=\"calender\"><table align=center border=0 width=140>" + "<tr>" + "<td align=left><a href='javascript:parent.opener.setPreviousMonth()' class='navigate'><</a></td>" + "<td style=\"font-weight:700; color:#ffffff; margin:0; padding:0; text-align:center;\">" + getMonth(calDate.getMonth()) + "</td>" + "<td align=left><a href='javascript:parent.opener.setNextMonth()' class='navigate'>></span></td>" + "</tr>";
    calDoc = calDoc + "<tr>" + "<td align=left><a href='javascript:parent.opener.setPreviousYear()' class='navigate'><</span></td>" + "<td style=\"font-weight:700; color:#ffffff; margin:0; padding:0; text-align:center;\">" + calDate.getFullYear() + "</td>" + "<td align=left><a href='javascript:parent.opener.setNextYear()' class='navigate'>></span></td>" + "</tr>" + "</table></div >" + calendarTable;
         month = calDate.getMonth();
         year = calDate.getFullYear();
    // Get globally tracked day value (prevents JavaScript date anomalies)
         day = calDay;
         var counter = 0;
         var days = getDaysInMonth();
    // If global day value is > than days in month, highlight last day in month
         if (day > days) {
              day = days;
    // Determine what day of the week the calendar starts on
         var firstOfMonth = new Date(year, month, 1);
    // Get the day of the week the first day of the month falls on
         var startingPos = firstOfMonth.getDay();
         days += startingPos;
         var columnCount = 0;
    // Make beginning non-date cells blank
         for (counter = 0; counter < startingPos; counter++) {
              calDoc += blankCell;
              columnCount++;
         var currentDay = 0;
         var dayType = "weekday";
    // Date cells contain a number
         for (counter = startingPos; counter < days; counter++) {
              var paddingChar = " ";
              if (counter - startingPos + 1 < 10) {
                   padding = "  ";
              } else {
                   padding = " ";
              currentDay = counter - startingPos + 1;
    // Set the type of day
              if (noDateSelected == 0 && (currentDay == startDay) && (startMonth == calDate.getMonth() && startYear == calDate.getYear())) {
                   dayType = "focusDay";
              } else {
                   if (noDateSelected == 1 && (currentDay == currentDate.getDate()) && (calDate.getMonth() == currentDate.getMonth())) {
                        dayType = "focusDay";
                   } else {
                        dayType = "weekDay";
              calDoc += "<td align=center bgcolor='" + cellColor + "'>" + "<a class='" + dayType + "' href='javascript:parent.opener.returnDate(" + currentDay + ")'>" + padding + currentDay + paddingChar + "</a></td>";
              columnCount++;
    // Start a new row when necessary
              if (columnCount % 7 == 0) {
                   calDoc += "</tr><tr>";
    // Make remaining non-date cells blank
         for (counter = days; counter < 42; counter++) {
              calDoc += blankCell;
              columnCount++;
    // Start a new row when necessary
              if (columnCount % 7 == 0) {
                   calDoc += "</tr>";
                   if (counter < 41) {
                        calDoc += "<tr>";
         calDoc += calendarEnd;
         return calDoc;
    Write the monthly calendar once the forward/backward arrow has been clicked on
    function writeCalendar() {
    // CREATE THE NEW CALENDAR FOR THE SELECTED MONTH & YEAR
         calDocBottom = buildBottomCalFrame();
         newWin.document.open();
         newWin.document.write(calDocBottom);
         newWin.document.close();
    Set the global date to the previous month and refresh the calendar
    function setPreviousMonth() {
         var year = calDate.getFullYear();
         var month = calDate.getMonth();
         // If month is January, set month to December and decrement the year
         if (month == 0) {
              month = 11;
              if (year > 1000) {
                   year--;
                   calDate.setFullYear(year);
         } else {
              month--;
         calDate.setMonth(month);
         writeCalendar();
    Set the global date to the previous year and refresh the calendar
    function setPreviousYear() {
         var year = calDate.getFullYear();
         year--;
         calDate.setYear(year);
         writeCalendar();
    // Set the global date to next month and refresh the calendar
    function setNextMonth() {
         var year = calDate.getFullYear();
         var month = calDate.getMonth();
    // If month is December, set month to January and increment the year
         if (month == 11) {
              month = 0;
              year++;
              calDate.setFullYear(year);
         } else {
              month++;
         calDate.setMonth(month);
         writeCalendar();
    // Set the global date to next year and refresh the calendar
    function setNextYear() {
         var year = calDate.getFullYear();
         year++;
         calDate.setYear(year);
         writeCalendar();
    Get number of days in the month
    function getDaysInMonth() {
         var days;
         var month = calDate.getMonth() + 1;
         var year = calDate.getFullYear();
         if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
              days = 31;
         } else {
              if (month == 4 || month == 6 || month == 9 || month == 11) {
                   days = 30;
              } else {
                   if (month == 2) {
                        if (isLeapYear(year)) {
                             days = 29;
                        } else {
                             days = 28;
         return (days);
    Check to see if the year is a leap year
    function isLeapYear(Year) {
         if (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0)) {
              return (true);
         } else {
              return (false);
    Build the month select list
    function getMonth(month) {
         monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    // Return a string value which contains a select list of all 12 months
         return monthArray[month];
    Set days of the week
    function createWeekdayList() {
         daysInWeekLongName = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
         daysInWeekShortName = new Array("Su", "Mo", "Tu", "We", "Th", "Fr", "Sa");
         var weekdays = "<tr bgcolor='" + headingCellColor + "'>";
    // Loop through the weekday array
         for (var index = 0; index < daysInWeekShortName.length; index++) {
              weekdays += "<td class='heading' align=center>" + daysInWeekShortName[index] + "</td>";
         weekdays += "</tr>";
    // Return table row of weekday abbreviations to display above the calendar
         return weekdays;
    Pre-build portions of the calendar (for performance reasons)
    function buildCalParts() {
    // Generate weekday headers for the calendar
         weekdays = createWeekdayList();
    // Build the blank cell rows
         blankCell = "<td align=center bgcolor='" + cellColor + "'>  </td>";
    // Build the top portion of the calendar page using CSS to control some display elements
         calendarBegin = "<html>" + "<head>" + "<TITLE>Calendar</TITLE>" + "<style>";
    calendarBegin = calendarBegin + "TD.heading { text-decoration: none; color: #ffffff; font: " + headingFontStyle + "; }";
    calendarBegin = calendarBegin + "B { text-decoration: none; color: #000000; font: " + headingFontStyle + "; }";
    calendarBegin = calendarBegin + "A.focusDay:link { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" + "A.focusDay:hover { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" + "A.focusDay:visited { color: #000000; text-decoration: none; font: " + fontStyle + "; }";
    calendarBegin = calendarBegin + "A.weekday:link { color: #000000; text-decoration: none; font: " + fontStyle + "; }" + "A.weekday:hover { color: " + hoverColor + "; font: " + fontStyle + "; }" + "A.weekday:visited { color: #000000; text-decoration: none; font: " + fontStyle + "; }";
    calendarBegin = calendarBegin + "A.navigate:link { font-weight:700; color:#ffffff; text-decoration: none; }" + "A.navigate:hover { font-weight:700; color:#ffffff; text-decoration: none; }" + "A.navigate:visited { font-weight:700; color:#ffffff; text-decoration: none; }";
    calendarBegin = calendarBegin + "</style>" + "</head>" + "<body style=\"background-color:#3d70d6; font:normal 75% arial, helvetica, sans-serif; text-align:center; margin:0; padding:0;\">" + "<center>";
    // Netscape needs a table container to display the table outlines properly
         if (isNav) {
              calendarTable = "<table CELLPADDING=0 CELLSPACING=1 border=" + tableBorder + " align=center bgcolor=\"" + tableBGColor + "\"><tr><td>" +
    // Build weekday headings
              "<table CELLPADDING=0 CELLSPACING=1 border=" + tableBorder + " align=center bgcolor=\"" + tableBGColor + "\">" + weekdays + "<tr>";
         } else {
    // Build weekday headings
              calendarTable = "<table CELLPADDING=0 CELLSPACING=1 border=" + tableBorder + " align=center bgcolor=\"" + tableBGColor + "\">" + weekdays + "<tr>";
    // Build the bottom portion of the calendar page
         calendarEnd = "";
    // Whether or not to display a thick line below the calendar
         if (bottomBorder) {
              calendarEnd += "<tr></tr>";
    // Netscape needs a table container to display the table outlines properly
         if (isNav) {
              calendarEnd += "</td></tr></table>";
    // End the table and the HTML document
         calendarEnd += "</table>" + "<a href='javascript: self.close ();' class='linktext' style=\"font-weight:700; color:#ffffff;\">Close Calendar Window</a>" + "</center>" + "</body>" + "</html>";
    // Set form field value to the date selected and close the calendar window
    function returnDate(selectedDay) {
         calDate.setDate(selectedDay);
    // Set the date returned to the user
         var day = "0" + calDate.getDate();
         day = day.substring(day.length - 2, day.length);
         var month = monthArray[calDate.getMonth()];
         month = month.substring(0, 3);
         dateField.value = day + "-" + month + "-" + calDate.getFullYear();
         //dateField.focus();
    // Close the calendar window
         if (updateAge === "true") {
              top.calculateAge();
         top.newWin.close();
    }

    Too much unformatted code to even try and understand.
    Is this a Java/JSP question or javascript issue?
    Is there an error message loading the page?
    Are there any javascript notifications (check the alert bottom left of IE browser)
    When does the error occur? Loading the page? Pushing the button?
    My suggestion would be to
    - view source on the generated HTML. See if the html is valid, and correct.
    - change the onclick event of the button to pop up an "alert" so you can see it is actually getting to the button press. Then put alerts through the code you are calling to see if it is actually getting there.
    cheers,
    evnafets

  • Multiple Fiscal Calendars Displayed in Subject Area Time Dimension

    Hi all,
    Thanks for taking the time to review my post.
    Environment
    Oracle BI Applications 7.9.6 Financial Analytics
    Oracle E-Business Suite 11.5.10
    Query
    The Time dimension on my Subject Areas (Financial Analytics) are showing more period data than I expected.
    I have configured one Enterprise Calendar (WPG_Calendar) that I set in the DAC parameters - $$GBL_CALENDAR_ID (WPG_Calendar~Month) and $$GBL_DATASOURCE_NUM_ID (4). The warehouse Enterprise Calendar table W_ENT_PERIOD_D is populating with the periods as configured in EBS for that calendar(Jan-09, Feb-0, Mar-09, etc). I noticed that the Multiple Fiscal W_MCAL_PERIOD_D table is also been populated with the Enterprise Calendar data PLUS, the Seeded EBS calendar (JEBE_MONTH_VAT) and a generated Calendar that appears to be a 5-4-5-4 Calendar (Jan-01-09, Jan-02-09, Jan-03-09, etc). The trouble is these W_MCAL_PERIOD_D periods and dates are all coming through in my Time dimensions and make it confusing for the Answers Users when choosing a Time dimension.
    Also, for columns W_CURRENT_MCAL_PERIOD_CODE, W_CURRENT_MCAL_QTR_CODE, W_CURRENT_MCAL_YEAR_CODE there are rows with Current, Previous and Next populated that span these different periods as you would expect, but I'm concerned these return multiple rows for Filters Current Fiscal Quater, Current Fiscal Year.
    Funnily enough, W_CURRENT_MCAL_MONTH_CODE has nothing populated (NULLs for all rows).
    Your comments are most welcome.
    Kind Regards,
    Gary.

    The filtering of the calendar can be done directly on the logical layer.
    for the logical dimension "Dim - Date Fiscal Calendar", Logical Table Source "Dim_W_MCAL_PERIOD_D_Fiscal_Period"
    set the content as :
    "Oracle Data Warehouse".Catalog.dbo.Dim_W_MCAL_PERIOD_D_Fiscal_Period.MCAL_CAL_WID = VALUEOF("MY_MCAL_WID")
    and setup the repository variable MY_MCAL_WID to match with your calendar wid.
    If your calendar depends on any context then you can use session variable instead of repository variable

  • [10g] Best way to populate and update multiple workday calendars?

    I would like to create multiple workday calendars, and be able to update them as needed. Each workday calendar would be for at most 5 years (right now), although it is possible that at some point in the future, I might want to extend that.
    A workday calendar can apply to a single resource or a group of resources. Each individual is part of a resource group. What I'm thinking is that if an individual resource has an associated workday calendar, that calendar gets used, but if it doesn't, it uses the calendar of it's resource group, and if the group doesn't have one, the default calendar gets used. Theoretically, each resource could have its own workday calendar, and there would be probably 500 resources at most. In practice, many resources will have the same or similar workday calendars.
    Each calendar will be based on one of 3 standards: all calendars days are work days, all days but weekends are workdays, or all days except weekends and holidays are workdays. (Weeks start on Sunday, and Saturday and Sunday are weekends.) The standard calendar would then be modified to create each unique calendar as needed. For example, if a resource was an employee, their calendar might be the standard of not working weekends or holidays, but could also include a one week vacation in February and a one week vacation July. I'm not sure what the best approach is for defining a calendar in the first place and then being able to update it as an employee decides on vacations (or whatever other situation might affect workdays).
    Furthermore, I'd really like to be able to incorporate work hours, which could vary by day, though would likely be fairly standard. I don't know if this information belongs in the workday table, or as something separate to be combined with the workday table.
    My ultimate purpose in doing all of this is to try to schedule a very large project amongst many resources.
    Here is some sample data illustrating where I'm at so far:
    CREATE TABLE     work_groups
    (     group_id     VARCHAR2(5)     NOT NULL
    ,     group_name     VARCHAR2(25)     
    ,     group_desc     VARCHAR2(200)
    ,     CONSTRAINT     work_groups_pk     PRIMARY KEY (group_id)
    INSERT INTO     work_groups
    VALUES     ('A','Group A','Group A description');
    INSERT INTO     work_groups
    VALUES     ('B','Group B','Group B description');
    INSERT INTO     work_groups
    VALUES     ('C','Group C','Group C description');
    INSERT INTO     work_groups
    VALUES     ('D','Group D','Group D description');
    CREATE TABLE     resources
    (     resource_id     VARCHAR2(20)     NOT NULL
    ,     type          VARCHAR2(1)
    ,     description     VARCHAR2(200)
    ,     group_id     VARCHAR2(5)     
    ,     CONSTRAINT     resources_pk     PRIMARY KEY (resource_id)
    ,     CONSTRAINT     group_id_fk     FOREIGN KEY (group_id)
                             REFERENCES  work_groups (group_id)
    INSERT INTO     resources
    VALUES     ('A001','M','text here','A');
    INSERT INTO     resources
    VALUES     ('A002','M','text here','A');
    INSERT INTO     resources
    VALUES     ('A003','M','text here','A');
    INSERT INTO     resources
    VALUES     ('B001','M','text here','B');
    INSERT INTO     resources
    VALUES     ('B002','M','text here','B');
    INSERT INTO     resources
    VALUES     ('C001','M','text here','C');
    INSERT INTO     resources
    VALUES     ('C002','M','text here','C');
    INSERT INTO     resources
    VALUES     ('C003','M','text here','C');
    INSERT INTO     resources
    VALUES     ('D001','M','text here','D');
    INSERT INTO     resources
    VALUES     ('12345','L','text here','A');
    INSERT INTO     resources
    VALUES     ('12346','L','text here','A');
    INSERT INTO     resources
    VALUES     ('12347','L','text here','B');
    INSERT INTO     resources
    VALUES     ('12348','L','text here','B');
    INSERT INTO     resources
    VALUES     ('12349','L','text here','C');
    INSERT INTO     resources
    VALUES     ('12350','L','text here','C');
    INSERT INTO     resources
    VALUES     ('12351','L','text here','D');I'm not sure if I should have a separate table to define a relationship between a resource or resource group and a calendar id (each resource or group would only be able to be assigned 1 unique calendar id, though multiple resources/groups could share the same calendar id), or if I should add an extra column to each of the above tables to assign the calendar id.
    CREATE TABLE     calendars
    (     cal_id          NUMBER(4)     NOT NULL
    ,     cal_title     VARCHAR2(25)
    ,     cal_desc     VARCHAR2(200)
    ,     CONSTRAINT     calendars_pk     PRIMARY KEY (cal_id)
    INSERT INTO     calendars
    VALUES     (1,'Default','This is the default calendar to use for workdays');
    INSERT INTO     calendars
    VALUES     (2,'All Days','This calendar treats all days as workdays');
    INSERT INTO     calendars
    VALUES     (3,'Weekends Off','This calendar gives weekends off, but no holidays');
    INSERT INTO     calendars
    VALUES     (4,'Holidays Off','This calendar gives weekends and holidays off');
    CREATE TABLE     workdays
    (     cal_id          NUMBER(4)     NOT NULL
    ,     cal_date     DATE          NOT NULL
    ,     cal_year     NUMBER(4)
    ,     work_day     NUMBER(3)
    ,     work_date     DATE
    ,     work_week     NUMBER(2)
    ,     work_year     NUMBER(4)
    ,     work_days     NUMBER(5)
    ,     cal_days     NUMBER(6)
    ,     CONSTRAINT     workdays_pk     PRIMARY KEY (cal_id, cal_date)
    ,     CONSTRAINT     cal_id_fk     FOREIGN KEY (cal_id)
                             REFERENCES  calendars (cal_id)
    );cal_id     - refers to calendars table
    cal_date - the actual calendar date
    cal_year - the actual calendar year for the given calendar date
    work_day - workday in that work year (resets each year, starting at 1, is 0 if that calendar date is not a work day)
    work_date - if a work day, the calendar date, if not, the calendar date of the last work day (or in the first week of the calendar, the next work day)
    work_week - work week of the work date (numbered starting at 1 , reset each year at the first Sunday of the year, before first Sunday will have last week of previous year, and the first year of the calendar will have all days prior to Sunday included in the first week, so the first week of a calendar could be more than 7 days)
    work_year - year of the work date
    work_days - shop day of the work date (except in first week of the calendar, before first shop day is 0), starts at 1 (at the beginning of the calendar), cummulative (does not reset each year)
    cal_days - calendar day of the work date, starts at 1 (at the beginning of the calendar), cummulative (does not reset each year)
    Assuming the calendar starts on 1/1/2010 (these values are approximately correct--I just made my best guess to provide sample data):
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/01/2010','mm/dd/yyyy'),2010,0,TO_DATE('01/04/2010','mm/dd/yyyy'),1,2010,0,1);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/02/2010','mm/dd/yyyy'),2010,0,TO_DATE('01/04/2010','mm/dd/yyyy'),1,2010,0,2);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/03/2010','mm/dd/yyyy'),2010,0,TO_DATE('01/04/2010','mm/dd/yyyy'),1,2010,0,3);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/04/2010','mm/dd/yyyy'),2010,1,TO_DATE('01/04/2010','mm/dd/yyyy'),1,2010,1,4);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/05/2010','mm/dd/yyyy'),2010,2,TO_DATE('01/05/2010','mm/dd/yyyy'),1,2010,2,5);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('12/23/2010','mm/dd/yyyy'),2010,250,TO_DATE('12/23/2010','mm/dd/yyyy'),51,2010,250,357);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('12/24/2010','mm/dd/yyyy'),2010,0,TO_DATE('12/23/2010','mm/dd/yyyy'),51,2010,250,358);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/01/2011','mm/dd/yyyy'),2011,0,TO_DATE('12/23/2010','mm/dd/yyyy'),51,2010,250,366);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/02/2011','mm/dd/yyyy'),2011,0,TO_DATE('12/23/2010','mm/dd/yyyy'),1,2011,250,367);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/03/2011','mm/dd/yyyy'),2011,1,TO_DATE('01/03/2010','mm/dd/yyyy'),1,2011,251,368);I've tried googling workday calendars and similar things, but I can't seem to find anything that fits my situation. If anyone could even point me in the right direction, I'd appreciate it.
    I'm working in 10g (XE).
    Edited by: user11033437 on Jul 19, 2011 3:05 PM
    Also, I don't know if it would make more sense to just somehow store the days each resource/group doesn't work, and generate a workday calendar on the fly as needed, rather than trying to store possibly thousands of dates in the database??

    Hi,
    Interesting problem!
    I'm not sure exactly what you want, however. Are you looking for a way to answer questions such as "For resource A001, what are the first 6 work days on or after January 4, 2010?" or "How many work days does resource A001 have between January 4 and January 12, 2010?" Post a few examples of the questions you might ask, and the results you would want, given the sample data you posted.
    user11033437 wrote:
    I would like to create multiple workday calendars, and be able to update them as needed. Each workday calendar would be for at most 5 years (right now), although it is possible that at some point in the future, I might want to extend that.
    A workday calendar can apply to a single resource or a group of resources. Each individual is part of a resource group. Is a "resouce group" the same as a "work group"?
    if a resource moves from one resource group to another, do you need to keep track of the historical information? For example, if resource A001 does not havfe its own calendar, and is part of work_group A on Juanuary 1, 2010, but then moves to work_group B on July 1, 2010, will you need to answer questions like "How many work days did A001 have in 2010", where you have to remember that the work_group A calendar apllied during the first half of the year, but the work_group B calendar was in use for the second half?
    What I'm thinking is that if an individual resource has an associated workday calendar, that calendar gets used, but if it doesn't, it uses the calendar of it's resource group, and if the group doesn't have one, the default calendar gets used. Theoretically, each resource could have its own workday calendar, and there would be probably 500 resources at most. In practice, many resources will have the same or similar workday calendars.
    Each calendar will be based on one of 3 standards: all calendars days are work days, all days but weekends are workdays, or all days except weekends and holidays are workdays. (Weeks start on Sunday, and Saturday and Sunday are weekends.) The standard calendar would then be modified to create each unique calendar as needed. For example, if a resource was an employee, their calendar might be the standard of not working weekends or holidays, but could also include a one week vacation in February and a one week vacation July. I'm not sure what the best approach is for defining a calendar in the first place and then being able to update it as an employee decides on vacations (or whatever other situation might affect workdays).It seems like the simplest thing would be to record only the exceptions to the base calendar. That is, given that the employee normally abides by the "no weekends or holidays" schedule, just enter 5 rows for that particular employee to mark the 5 work days he'll miss in February. If the emplyoee is going to work Saturdays in June (in addition to his regular schedule), then enter one row for each Saturday in June.
    >
    Furthermore, I'd really like to be able to incorporate work hours, which could vary by day, though would likely be fairly standard. I don't know if this information belongs in the workday table, or as something separate to be combined with the workday table. That depends on exactly what you want. Post a couple opf examples of questions you would want to answer, and the actual answers, given the sample data you post.
    My ultimate purpose in doing all of this is to try to schedule a very large project amongst many resources.
    Here is some sample data illustrating where I'm at so far:
    CREATE TABLE     work_groups
    (     group_id     VARCHAR2(5)     NOT NULL
    ,     group_name     VARCHAR2(25)     
    ,     group_desc     VARCHAR2(200)
    ,     CONSTRAINT     work_groups_pk     PRIMARY KEY (group_id)
    INSERT INTO     work_groups
    VALUES     ('A','Group A','Group A description');
    INSERT INTO     work_groups
    VALUES     ('B','Group B','Group B description');
    INSERT INTO     work_groups
    VALUES     ('C','Group C','Group C description');
    INSERT INTO     work_groups
    VALUES     ('D','Group D','Group D description');
    CREATE TABLE     resources
    (     resource_id     VARCHAR2(20)     NOT NULL
    ,     type          VARCHAR2(1)
    ,     description     VARCHAR2(200)
    ,     group_id     VARCHAR2(5)     
    ,     CONSTRAINT     resources_pk     PRIMARY KEY (resource_id)
    ,     CONSTRAINT     group_id_fk     FOREIGN KEY (group_id)
                             REFERENCES  work_groups (group_id)
    INSERT INTO     resources
    VALUES     ('A001','M','text here','A');
    INSERT INTO     resources
    VALUES     ('A002','M','text here','A');
    INSERT INTO     resources
    VALUES     ('A003','M','text here','A');
    INSERT INTO     resources
    VALUES     ('B001','M','text here','B');
    INSERT INTO     resources
    VALUES     ('B002','M','text here','B');
    INSERT INTO     resources
    VALUES     ('C001','M','text here','C');
    INSERT INTO     resources
    VALUES     ('C002','M','text here','C');
    INSERT INTO     resources
    VALUES     ('C003','M','text here','C');
    INSERT INTO     resources
    VALUES     ('D001','M','text here','D');
    INSERT INTO     resources
    VALUES     ('12345','L','text here','A');
    INSERT INTO     resources
    VALUES     ('12346','L','text here','A');
    INSERT INTO     resources
    VALUES     ('12347','L','text here','B');
    INSERT INTO     resources
    VALUES     ('12348','L','text here','B');
    INSERT INTO     resources
    VALUES     ('12349','L','text here','C');
    INSERT INTO     resources
    VALUES     ('12350','L','text here','C');
    INSERT INTO     resources
    VALUES     ('12351','L','text here','D');
    It looks like all the rows have the same description. if description matters in this problem, wouldn't it be better to illustrate how it matters, by having different descrioptions that appeared in different outputs? On the other hand, if description doesn't play any role in this problem, then why include in the sample data at all?
    I'm not sure if I should have a separate table to define a relationship between a resource or resource group and a calendar id (each resource or group would only be able to be assigned 1 unique calendar id, though multiple resources/groups could share the same calendar id), or if I should add an extra column to each of the above tables to assign the calendar id.
    CREATE TABLE     calendars
    (     cal_id          NUMBER(4)     NOT NULL
    ,     cal_title     VARCHAR2(25)
    ,     cal_desc     VARCHAR2(200)
    ,     CONSTRAINT     calendars_pk     PRIMARY KEY (cal_id)
    INSERT INTO     calendars
    VALUES     (1,'Default','This is the default calendar to use for workdays');
    INSERT INTO     calendars
    VALUES     (2,'All Days','This calendar treats all days as workdays');
    INSERT INTO     calendars
    VALUES     (3,'Weekends Off','This calendar gives weekends off, but no holidays');
    INSERT INTO     calendars
    VALUES     (4,'Holidays Off','This calendar gives weekends and holidays off');
    What is is cal_id=1? How will it differ from the other three?
    CREATE TABLE     workdays
    (     cal_id          NUMBER(4)     NOT NULL
    ,     cal_date     DATE          NOT NULL
    ,     cal_year     NUMBER(4)
    ,     work_day     NUMBER(3)
    ,     work_date     DATE
    ,     work_week     NUMBER(2)
    ,     work_year     NUMBER(4)
    ,     work_days     NUMBER(5)
    ,     cal_days     NUMBER(6)
    ,     CONSTRAINT     workdays_pk     PRIMARY KEY (cal_id, cal_date)
    ,     CONSTRAINT     cal_id_fk     FOREIGN KEY (cal_id)
                             REFERENCES  calendars (cal_id)
    );I suspect there's a simpler way, especially if there's a regular order to day types (e.g., people who get holidays off normally get weekeneds, too).
    Perhaps you could have a table like this, that had one row per day:
    CREATE TABLE  days
    (       a_date      DATE     PRIMARY KEY
    ,     day_type    NUMBER (1)              -- 1=Weekend, 2=Holiday, 3=Other
    INSERT INTO days (a_date, day_type) VALUES (DATE '2010-01-01', 2) /* New Years Day */;
    INSERT INTO days (a_date, day_type) VALUES (DATE '2010-01-02', 1) /* Saturday */;
    INSERT INTO days (a_date, day_type) VALUES (DATE '2010-01-03', 1) /* Sunday */;
    INSERT INTO days (a_date, day_type) VALUES (DATE '2010-01-04', 3) /* Monday - back to work */;
    ...Another table (I'll call it work_sched) shows what resources work when:
    CREATE TABLE  work_sched
    (       p_key          NUMEBR     PRIMARY KEY     -- Arbitrary Unique ID
    ,     group_id         VARCHAR2 (5)          -- Exactly one of the columns group_id or ...
    ,     resource_id      VARCHAR2 (20)          --     ... resource_id will always be NULL
    ,     a_date              DATE
    ,     works_on     NUMBER (1)          -- works when days.day_type >= this value
    ,     remarks          VARCHAR2 (40)
    );To indicate that work_group 'L' normally works on type 3 days only (that is, weekends or holidays):
    INSERT INTO work_sched (group_id, a_date, works_on) VALUES ('L', NULL, 3);(Let's assume that p_key is populated by a trigger.)
    The NULL in the a_date column indicates that this applies to all days, unless overridden by another row in the work_sched table. Instead of NULL, mabe some impossible date (such as Jan. 1, 1900) would be more convenient to indicate defaults.
    Exceptions to this schedule would be indicated by other rows in work_sched. For example, if '12345' is the employee who's on vacation for a week in February:
    INSERT INTO work_sched (resource_id, a_date, works_on, remarks) VALUES ('12345', DATE '2010-02-08', 4, 'Vacation');
    INSERT INTO work_sched (resource_id, a_date, works_on, remarks) VALUES ('12345', DATE '2010-02-09', 4, 'Vacation');
    INSERT INTO work_sched (resource_id, a_date, works_on, remarks) VALUES ('12345', DATE '2010-02-10', 4, 'Vacation');
    INSERT INTO work_sched (resource_id, a_date, works_on, remarks) VALUES ('12345', DATE '2010-02-11', 4, 'Vacation');
    INSERT INTO work_sched (resource_id, a_date, works_on, remarks) VALUES ('12345', DATE '2010-02-12', 4, 'Vacation');And if that same employee works Satudays in June:
    INSERT INTO work_sched (resource_id, a_date, works_on, remarks) VALUES ('12345', DATE '2010-06-05', 1, 'Fiscal year-end crunch');
    INSERT INTO work_sched (resource_id, a_date, works_on, remarks) VALUES ('12345', DATE '2010-06-12', 1, 'Fiscal year-end crunch');
    INSERT INTO work_sched (resource_id, a_date, works_on, remarks) VALUES ('12345', DATE '2010-06-19', 1, 'Fiscal year-end crunch');
    INSERT INTO work_sched (resource_id, a_date, works_on, remarks) VALUES ('12345', DATE '2010-06-26', 1, 'Fiscal year-end crunch');When finding the number of work days, we would join work_sched to days using both conditions:
    ON   work_sched.date           = days.a_date
    AND  work_sched.works_on  <= days.day_type
    cal_id     - refers to calendars table
    cal_date - the actual calendar date
    cal_year - the actual calendar year for the given calendar date
    work_day - workday in that work year (resets each year, starting at 1, is 0 if that calendar date is not a work day)
    work_date - if a work day, the calendar date, if not, the calendar date of the last work day (or in the first week of the calendar, the next work day)
    work_week - work week of the work date (numbered starting at 1 , reset each year at the first Sunday of the year, before first Sunday will have last week of previous year, and the first year of the calendar will have all days prior to Sunday included in the first week, so the first week of a calendar could be more than 7 days)
    work_year - year of the work date
    work_days - shop day of the work date (except in first week of the calendar, before first shop day is 0), starts at 1 (at the beginning of the calendar), cummulative (does not reset each year)
    cal_days - calendar day of the work date, starts at 1 (at the beginning of the calendar), cummulative (does not reset each year)This is a lot of denormalized data. that is, you should be able to easily deduce cal_year from cal_date, but sometimes it is convenient to store denormalized data.
    Assuming the calendar starts on 1/1/2010 (these values are approximately correct--I just made my best guess to provide sample data):
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/01/2010','mm/dd/yyyy'),2010,0,TO_DATE('01/04/2010','mm/dd/yyyy'),1,2010,0,1);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/02/2010','mm/dd/yyyy'),2010,0,TO_DATE('01/04/2010','mm/dd/yyyy'),1,2010,0,2);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/03/2010','mm/dd/yyyy'),2010,0,TO_DATE('01/04/2010','mm/dd/yyyy'),1,2010,0,3);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/04/2010','mm/dd/yyyy'),2010,1,TO_DATE('01/04/2010','mm/dd/yyyy'),1,2010,1,4);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/05/2010','mm/dd/yyyy'),2010,2,TO_DATE('01/05/2010','mm/dd/yyyy'),1,2010,2,5);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('12/23/2010','mm/dd/yyyy'),2010,250,TO_DATE('12/23/2010','mm/dd/yyyy'),51,2010,250,357);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('12/24/2010','mm/dd/yyyy'),2010,0,TO_DATE('12/23/2010','mm/dd/yyyy'),51,2010,250,358);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/01/2011','mm/dd/yyyy'),2011,0,TO_DATE('12/23/2010','mm/dd/yyyy'),51,2010,250,366);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/02/2011','mm/dd/yyyy'),2011,0,TO_DATE('12/23/2010','mm/dd/yyyy'),1,2011,250,367);
    INSERT INTO     workdays
    VALUES     (3, TO_DATE('01/03/2011','mm/dd/yyyy'),2011,1,TO_DATE('01/03/2010','mm/dd/yyyy'),1,2011,251,368);I've tried googling workday calendars and similar things, but I can't seem to find anything that fits my situation. If anyone could even point me in the right direction, I'd appreciate it.
    I'm working in 10g (XE).
    Edited by: user11033437 on Jul 19, 2011 3:05 PM
    Also, I don't know if it would make more sense to just somehow store the days each resource/group doesn't work, and generate a workday calendar on the fly as needed, rather than trying to store possibly thousands of dates in the database??That's what I was thinking, too.
    Post some sample data (if it's not what you've already posted), a couple of sample questions, and the exact answers you want from each question given that sample data.

Maybe you are looking for

  • Error Synchronizing BB 8330 with MS Outlook

    I have tried several times to synchronize my calendar with Outlook and I get a dialog it says "Error encountered. Error code - 0x80040fb3. Check documentation. I have made a search in BB web site but I do not found anything. Can any one give me any t

  • Cmd C, V not functioning correctly

    Just got my hands on a shiny new Retina MacBook Pro, one problem though. When trying to copy (CMD+C) and paste (CMD+V) it does nothing. If I'm in finder and select a file followed by CMD+C it opens up a new finder window under the search part. This h

  • Zen Micro Battery L

    I was just wondering what the longest was that anyone got a battery to last in a zen micro. I have managed to get mine to last approx 4hrs. Has anyone else had this sucess? Blade

  • Datawindow Filter question

    Not sure if this is a bug/bad dw or the way it is suppose to work and I just never noticed before.... If I update a column in the filter buffer I would expect it to be saved when the update occurs. But that is not what's happens it looks as if the da

  • DNS Settings have Changed with Snow Leopard Update

    Before I upgraded to SL, I was able to append a DNS server to the list of servers that my MacBook Pro acquired from the DHCP server. This way, I didn't have to manually edit my DNS settings all the time when I was in the office and wanted to access o