Break Date Range by Week / Month

I have an ArrayCollection which is made up of Objects in the following form:
AC = { site='abc.com' date="2009-10-01" visits="2000" ...},
     { site='abc.com' date="2009-10-02" visits="2000" },
     { site='abc.com' date="2009-10-03" visits="2000" },
     { site='abc.com' date="2009-10-04" visits="2000" },
     { site='abc.com' date="2009-10-04" visits="2000" },
     { site='abc.com' date="2009-10-05" visits="2000" },
     { site='abc.com' date="2009-10-06" visits="2000" },
     { site='abc.com' date="2009-10-07" visits="2000" },
     { site='abc.com' date="2009-10-08" visits="2000" },
     { site='xyz.com' date="2009-10-01" visits="2000" },
     { site='xyz.com' date="2009-10-02" visits="2000" },
     { site='xyz.com' date="2009-10-03" visits="2000" },
     { site='xyz.com' date="2009-10-04" visits="2000" },
I'd like to break up this ArrayCollection into Weeks and Months. As in, group them into an Advanced Datagrid by Group Week.
I imagine I should be adding a key to each object that specifies Week 1, Week 2, etc; by getting the getDay() to being 1 (for Mondays), and the result would be:
AC = { site='abc.com' date="2009-10-01" visits="2000" week="Week1"},
     { site='abc.com' date="2009-10-02" visits="2000" week="Week1"},
     { site='abc.com' date="2009-10-03" visits="2000" week="Week1"},
     { site='abc.com' date="2009-10-04" visits="2000" week="Week1"},
     { site='abc.com' date="2009-10-04" visits="2000" week="Week1"},
     { site='abc.com' date="2009-10-05" visits="2000" week="Week1"},
     { site='abc.com' date="2009-10-06" visits="2000" week="Week1"},
     { site='abc.com' date="2009-10-07" visits="2000" week="Week1"},
     { site='abc.com' date="2009-10-08" visits="2000" week="Week2"},
     { site='abc.com' date="2009-10-09" visits="2000" week="Week2"},
     { site='abc.com' date="2009-10-10" visits="2000" week="Week2"},
     { site='xyz.com' date="2009-10-01" visits="2000" week="Week1"},
     { site='xyz.com' date="2009-10-02" visits="2000" week="Week1"},
     { site='xyz.com' date="2009-10-03" visits="2000" week="Week1"},
     { site='xyz.com' date="2009-10-04" visits="2000" week="Week1" },
Anybody got any other ideas?

Hi,
here's one way:
WITH     params          AS
     SELECT  DATE '2012-08-01'     AS p_from_date
     ,     DATE '2012-09-19'     AS p_to_date
     FROM     dual
,     end_points     AS
     SELECT     TRUNC ( p_from_date + 4
                , 'IW'
                ) + 3          AS first_thursday
     ,     TRUNC ( p_to_date + 4
                , 'IW'
                ) - 5          AS last_wednesday
     FROM    params
SELECT     first_thursday + (7 * (LEVEL - 1))     AS week_start_date
,     first_thursday + (7 * LEVEL) - 1     AS week_end_date
FROM     end_points
CONNECT BY     LEVEL     <= ( last_wednesday
                  + 1
                  - first_thursday
                  ) / 7
;TRUNC (dt) is the beginning of the ISO week that contains the DATE dt.
The "magic number" 4 is used because the ISO week begins on Monday, 4 days later than your week begins, so
TRUNC ( dt + 4
      , 'IW'
      )is the Monday in the same Thursday-Wednesday week as dt.

Similar Messages

  • Date range by week based on input parameters

    Afternoon folks -- I need to produce a report which will be displayed based on weeks.
    There are two input parameters: P_FROM_DATE and P_TO_DATE
    I need to find the date ranges in weeks starting on THURSDAY and ending on a WEDNESDAY. For example, if my P_FROM_DATE is 01-AUG-2012 and P_TO_DATE is 11-SEP-2012, I need to show the following weeks in this fashion:
    02-AUG-2012 - 08-AUG-2012
    09-AUG-2012 - 15-AUG-2012
    16-AUG-2012 - 22-AUG-2012
    23-AUG-2012 - 29-AUG-2012
    30-AUG-2012 - 05-SEP-2012
    06-SEP-2012 - 12-SEP-2012So, the idea is to start the first THURSDAY following the P_FROM_DATE and end on the WEDNESDAY preceding the P_END_DATE..
    Thanks!

    Hi,
    here's one way:
    WITH     params          AS
         SELECT  DATE '2012-08-01'     AS p_from_date
         ,     DATE '2012-09-19'     AS p_to_date
         FROM     dual
    ,     end_points     AS
         SELECT     TRUNC ( p_from_date + 4
                    , 'IW'
                    ) + 3          AS first_thursday
         ,     TRUNC ( p_to_date + 4
                    , 'IW'
                    ) - 5          AS last_wednesday
         FROM    params
    SELECT     first_thursday + (7 * (LEVEL - 1))     AS week_start_date
    ,     first_thursday + (7 * LEVEL) - 1     AS week_end_date
    FROM     end_points
    CONNECT BY     LEVEL     <= ( last_wednesday
                      + 1
                      - first_thursday
                      ) / 7
    ;TRUNC (dt) is the beginning of the ISO week that contains the DATE dt.
    The "magic number" 4 is used because the ISO week begins on Monday, 4 days later than your week begins, so
    TRUNC ( dt + 4
          , 'IW'
          )is the Monday in the same Thursday-Wednesday week as dt.

  • Breaking Date Range in Query...

    Hi Friends,
    I have a Table which calculates Leaves taken by employees. The Leave Start date and End Date is in Range. i.e. Leave is from say 10th March 2006 to 15th March 2006. I need to generate a report for each day of the Leave. I.e. report needs a record for 10th, 11th,12th,13th,14th,15th. How can I break the date range into individual dates betn that range in a SQL Query..?
    thanks a lot,
    Jalpan Pota

    You can do it with a pipelined function. I have posted Re: Quarters Missing.?? that produces a range of quarters for a given date range. You should be easily able to amend this so that it produces a range of dates. Note that you will need to create a type that is a nested table of dates.
    Cheers, APC

  • How to set variant which gives date range of last month for sel.scr field

    Hi All,
    I want to set a variant which can do dynamic date calculation, need get last month period i.e when i select a variant it should always pick last month start date & end date for the period selection field. How can i achieve that. Please help me to know that.
    Thanks in advance.
    Regards
    Vishal

    I think in the date selection you can put in the calculations last month start date and end date, did you see what options you are getting in the variant? I am not in front of the system, so can't see.
    <b>I just looked up and found that you can specify the first and last day of the last month in the variant dynamic value setting.</b> When you saving the variant, select the check box for the SELECTION VARIABLE and then click the dynamic value calculation second traffic light. Then you will get drop down where you can select the values.
    Regards,
    Ravi
    Note : Please mark all the helpful answers
    Message was edited by: Ravikumar Allampallam

  • Query to get date range in Week

    Hello all,
    I wanted the get the results in terms of week like, if sysdate is 26/7/2007 Then
    I have to get previous 7 weeks including the week where sysdate exists.
    Results should come in this manner
    23rd to 27th 1 week
    16 - 20th July 2007 as 2nd week like this till 7 weeks
    I have a query but it is not giving in the above manner
    So please anybody can make a query as mentioned above.
    Query:
    SELECT TO_DATE(TO_CHAR(SYSDATE,'DD-MON-YYYY')) + ( ROWNUM - 6)+(ROWNUM+2)D,TO_DATE(TO_CHAR(SYSDATE,'DD-MON-YYYY')) + ( ROWNUM - 6)+(ROWNUM+2) R FROM DUAL CONNECT BY LEVEL < 6

    What do you want?
    -- A week
    select sysdate, sysdate+7 from dual;
    --A week from monday to sunday
    select nexT_DAY(SYSDATE, 'MONDAY'), NEXT_day(sysdate-7, 'SUNDAY') FROM DUAL
    BE CAREFUL MONDAY AND SUNDAY IF YOUR DDBB IS IN ENGLISH
    select
    nexT_DAY(SYSDATE, 'MONDAY'), NEXT_day(sysdate-7, 'SUNDAY'), TO_char(sysdate,'d'),
    (sysdate -TO_char(sysdate,'d')) as firstone,
    (sysdate + 7-TO_char(sysdate,'d') )as lastone
    FROM DUAL
    Message was edited by:
    cth

  • Crystal Week, Month and Quartely formula

    Hi experts,
    I have developed a crystal report with date fields. I want a formula that will make the dates range into weeks ,months and Quarter. Please Urgent Help will be appreciated.
    Regards
    Justice

    Hi Justice,
    Dateadd() function and lastfullmonth()  date in 1st qtr , 2nd qtr, etc will answer most of date rage formulas.
    example to get last week data then u can use {date} in lastfullweek()
    or you can arrive last week / month / qtr / year date using dateadd()
    dateadd('w',-1,{date})
    Thanks,
    Sastry

  • Date range

    Hi,
    How do I group by to have a date range count and it will sum up the letter1 that is obtained from that one month.Currently i knwo how to run it daily but summarizing by one month of teh postcodes, i am not too sure.
    This is table counters.
    Date Postcode Letter1 Letter2
    31/05/2009     810     MOM MOM
    1/01/2009     810     MOM MOM
    1/02/2009      810     MOM MOM
    29/05/2009     812     DAD DAD
    30/04/2009     832     DAD
    31/05/2009     835     DAD
    29/05/2009     812     MOM
    29/05/2009     812     MOM MOM
    DDL
    create table counters
    (DATETIME date,
    Postcode number,
    letter1 varchar2(5),
    letter 2 varchar2(5));
    Query I have tried:
    <pre>
    SELECT TO_CHAR(DATETIME, 'DD/MM/YY'),POSTCODE,
    count(letter1) as letter1_TOTAL,
    count(letter2) as letter2_TOTAL,
    sum(case when letter1 ='MOM' then 1 else 0 end) as "MOM",
    sum(case when letter2 ='DAD' then 1 else 0 end) as "DATE"
    FROM counters
    WHERE DATETIME >= (sysdate -180)
    GROUP BY TO_CHAR(DATETIME, 'DD/MM/YY'),POSTCODE
    ORDER BY TO_CHAR (DATETIME,'DD/MM/YY') DESC;
    </pre>
    Not sure how to do this month based.
    Liek my expected results should be
    Date Postcode letter1 letter2
    1/01/2009 -1/02/2009 810 2 null --------->MOM occured twice in that month
    1/03/2009 -1/04/2009 810 null null
    1/05/2009 -1/06/2009 810 1 null
    1/01/2009 -1/02/2009 812 null null
    1/03/2009 -1/04/2009 812 null null
    1/05/2009 -1/06/2009 812 1 1
    At that one month how many times MOM/DAD has summed up in that postcode.
    Edited by: CrackerJack on Jun 3, 2009 10:30 PM

    Still not very clear about our requirement.
    SQL> WITH counters AS
      2       (SELECT TO_DATE ('31/05/2009', 'DD/MM/YYYY') datetime, 810 postco
      3               'MOM' letter1, 'MOM' letter2
      4          FROM DUAL
      5        UNION ALL
      6        SELECT TO_DATE ('1/01/2009', 'DD/MM/YYYY'), 810, 'MOM', 'MOM'
      7          FROM DUAL
      8        UNION ALL
      9        SELECT TO_DATE ('1/02/2009', 'DD/MM/YYYY'), 810, 'MOM', 'MOM'
    10          FROM DUAL
    11        UNION ALL
    12        SELECT TO_DATE ('29/05/2009', 'DD/MM/YYYY'), 812, 'DAD', 'DAD'
    13          FROM DUAL
    14        UNION ALL
    15        SELECT TO_DATE ('30/04/2009', 'DD/MM/YYYY'), 832, 'DAD', NULL
    16          FROM DUAL
    17        UNION ALL
    18        SELECT TO_DATE ('31/05/2009', 'DD/MM/YYYY'), 835, 'DAD', NULL
    19          FROM DUAL
    20        UNION ALL
    21        SELECT TO_DATE ('29/05/2009', 'DD/MM/YYYY'), 812, 'MOM', NULL
    22          FROM DUAL
    23        UNION ALL
    24        SELECT TO_DATE ('29/05/2009', 'DD/MM/YYYY'), 812, 'MOM', 'MOM'
    25          FROM DUAL)
    26  SELECT * FROM COUNTERS
    27  ORDER BY datetime
    28  /
    DATETIME    POSTCODE LET LET
    01-JAN-09        810 MOM MOM
    01-FEB-09        810 MOM MOM
    30-APR-09        832 DAD
    29-MAY-09        812 MOM MOM
    29-MAY-09        812 DAD DAD
    29-MAY-09        812 MOM
    31-MAY-09        835 DAD
    31-MAY-09        810 MOM MOM
    8 rows selected.I changed your group by clause to include the date range. However if you want month wise you should understand that 01-Jan-2009 to 31-Jan 2009 is considered as one month. So the date range for one month you specified in your expected result was wrong. (01-Jan-2009 to 01-Feb-2009) .
    Hope the following code helps:
    SQL> WITH counters AS
      2       (SELECT TO_DATE ('31/05/2009', 'DD/MM/YYYY') datetime, 810 postco
      3               'MOM' letter1, 'MOM' letter2
      4          FROM DUAL
      5        UNION ALL
      6        SELECT TO_DATE ('1/01/2009', 'DD/MM/YYYY'), 810, 'MOM', 'MOM'
      7          FROM DUAL
      8        UNION ALL
      9        SELECT TO_DATE ('1/02/2009', 'DD/MM/YYYY'), 810, 'MOM', 'MOM'
    10          FROM DUAL
    11        UNION ALL
    12        SELECT TO_DATE ('29/05/2009', 'DD/MM/YYYY'), 812, 'DAD', 'DAD'
    13          FROM DUAL
    14        UNION ALL
    15        SELECT TO_DATE ('30/04/2009', 'DD/MM/YYYY'), 832, 'DAD', NULL
    16          FROM DUAL
    17        UNION ALL
    18        SELECT TO_DATE ('31/05/2009', 'DD/MM/YYYY'), 835, 'DAD', NULL
    19          FROM DUAL
    20        UNION ALL
    21        SELECT TO_DATE ('29/05/2009', 'DD/MM/YYYY'), 812, 'MOM', NULL
    22          FROM DUAL
    23        UNION ALL
    24        SELECT TO_DATE ('29/05/2009', 'DD/MM/YYYY'), 812, 'MOM', 'MOM'
    25          FROM DUAL)
    26  SELECT      TO_CHAR (TRUNC (datetime, 'MONTH'), 'DD/MM/YYYY')
    27           || '-'
    28           || TO_CHAR (LAST_DAY (datetime), 'DD/MM/YYYY') date_range,
    29           postcode, COUNT (letter1) AS letter1_total,
    30           COUNT (letter2) AS letter2_total,
    31           SUM (CASE
    32                   WHEN letter1 = 'MOM'
    33                      THEN 1
    34                   ELSE 0
    35                END) AS "MOM", SUM (CASE
    36                                       WHEN letter2 = 'DAD'
    37                                          THEN 1
    38                                       ELSE 0
    39                                    END) AS "DAD"
    40      FROM counters
    41     WHERE datetime >= (SYSDATE - 180)
    42  GROUP BY    TO_CHAR (TRUNC (datetime, 'MONTH'), 'DD/MM/YYYY')
    43           || '-'
    44           || TO_CHAR (LAST_DAY (datetime), 'DD/MM/YYYY'),
    45           postcode
    46  ORDER BY    TO_CHAR (TRUNC (datetime, 'MONTH'), 'DD/MM/YYYY')
    47           || '-'
    48           || TO_CHAR (LAST_DAY (datetime), 'DD/MM/YYYY')
    49  /
    DATE_RANGE              POSTCODE LETTER1_TOTAL LETTER2_TOTAL        MOM         DAD
    01/01/2009-31/01/2009        810             1             1          1           0
    01/02/2009-28/02/2009        810             1             1          1           0
    01/04/2009-30/04/2009        832             1             0          0           0
    01/05/2009-31/05/2009        810             1             1          1           0
    01/05/2009-31/05/2009        812             3             2          2           1
    01/05/2009-31/05/2009        835             1             0          0           0
    6 rows selected.Regards,
    Jo
    Edit: Added code tags

  • Missing date range in select

    Hello,
    Database Version 10gr2(10.2.0.5)
    This following data set is from my query, which the date range is weekly, where two week's date is missing (that's correct, because no data for those weeks). But I need to include that week date aslso with null or 0 values on. How to I select the running weeks from the following
    Current data set
    col1     week_date
    4     04/14/2012
    6     04/21/2012
    5     05/12/2012
    10     05/19/2012
    2     05/26/2012
    Expected result set
    col1     week_date
    4     04/14/2012
    6     04/21/2012
    *0     04/28/2012*
    *0     05/05/2012*
    5     05/12/2012
    10     05/19/2012
    2     05/26/2012Any help would be greatly appreciated.
    Thanks,

    Hi,
    You can use CONNECT BY to gerenate all the dates you need, then outer join your actualdata to that result set, like this:
    VARIABLE     start_date     VARCHAR2 (20)
    VARIABLE     end_date     VARCHAR2 (20)
    EXEC  :start_date := '04/14/2012';
    EXEC  :end_date   := '05/26/2012';
    WITH     all_dates     AS
         SELECT     TO_DATE (:start_date, 'MM/DD/YYYY')     + (7 * (LEVEL - 1))     AS week_date
         FROM     dual
         CONNECT BY     LEVEL <= 1 + ( ( TO_DATE (:end_date,   'MM/DD/YYYY')
                                     - TO_DATE (:start_date, 'MM/DD/YYYY')
                             / 7
    SELECT       COUNT (x.week_date)     AS col1
    ,       a.week_date
    FROM           all_dates  a
    LEFT OUTER JOIN  table_x    x  ON  a.week_date = x.week_date
    GROUP BY  a.week_date
    ORDER BY  a.week_date
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}
    Edited by: Frank Kulash on May 21, 2012 5:05 PM

  • Restrict Query Data based on Date range and Users

    Hi All,
    I have a few web reports that I need do restrict data based on Users.
    In all the queries i have an infoobject 0CALDAY, and  a User Entry range variable on it. Because of performance issues  I need to restrict the range of dates a User can see. Typically most of users could go to a max date range of 1 month back. But some others would need the ability to see data for much bigger range of dates.
    Pls suggest how should i go about with this. Should I have to enforce this at Variable level(user exit).... but then i might have to maintain a table for the users.. Is there any other way of doing it.
    thanks
    Raj

    Any thoughts ?

  • [MDX] Define date range based on user selection

    Hi All,
    I'm trying to define date range (of 3 months) using mdx based on user selection.
    This is what I'm trying to do:
    - If user select 2013, I would like range to be: from
    1 Oct 2013 to 31 Dec 2013
    - If user select Aug 2013, I would like range to be: from
    1 Jun 2013 to 31 Aug 2013
    - If user select 15 Sep 2013, I would like range to be : from
    15 Jul 2013 to 15 Sep 2013
    It is not a problem to get the upper bound of the range like this:
    ClosingPeriod(
    [Date].[Calendar].[Date],
    [Date].[Calendar].CurrentMember
    But I'm not able to get the lower bound of the range:
    OpeningPeriod(
    [Date].[Calendar].[Date],
    ParallelPeriod(
    [Date].[Calendar].[Month Number],
    2,
    ClosingPeriod(
    [Date].[Calendar].[Date],
    [Date].[Calendar].CurrentMember
    Error:If user selection is
    15 Aug 2013, I get
    14 Jun 2013
    If user selection is Apr 2013, I get
    (null)
    And even more strange, if user selection is
    2013, I get 28 Oct 2013
    Any idea of how to solve this ?
    Thanks,
    Guillaume

    Hello Guillaume,
    Can you please check if the following works for you? By the way, the performance will suffer due to all these IIF, the solution is very complex in order to avoid null in ParallelPeriod.
    with member measures.high as MemberToStr(ClosingPeriod(
       [Date].[Calendar].[Date],
       [Date].[Calendar].CurrentMember
    member measures.low as
    MemberToStr(
    iif(ClosingPeriod(
       [Date].[Calendar].[Date],
       [Date].[Calendar].CurrentMember
    ) IS ClosingPeriod(
       [Date].[Calendar].[Date],
       [Date].[Calendar].CurrentMember
    ).Parent.LastChild  --last date of the month
    OpeningPeriod(
       [Date].[Calendar].[Date],
    Ancestor(ClosingPeriod(
       [Date].[Calendar].[Date],
       [Date].[Calendar].CurrentMember
    ), [Date].[Calendar].[Month]).lag(2)
    iif([Date].[Calendar].CurrentMember.level is
    [Date].[Calendar].[Date]
    and
    Right(CSTR([Date].[Calendar].CurrentMember.Properties("KEY0")),4)="0429" --take care of 4/29
    OpeningPeriod(
       [Date].[Calendar].[Date],
    Ancestor(ClosingPeriod(
       [Date].[Calendar].[Date],
       [Date].[Calendar].CurrentMember
    ), [Date].[Calendar].[Month]).lag(2)
    OpeningPeriod(
       [Date].[Calendar].[Date],
       ParallelPeriod(
          [Date].[Calendar].[Month],
          2,
          ClosingPeriod(
             [Date].[Calendar].[Date],
             [Date].[Calendar].CurrentMember
    select  {measures.low,measures.high } on 0
    from [Adventure Works]
    where
    --[Date].[Calendar].[Date].&[20070815]
    --get [Date].[Calendar].[Date].&[20070615]
    --[Date].[Calendar].[Date].&[20070530]
    --get[Date].[Calendar].[Date].&[20070330]
    --[Date].[Calendar].[Date].&[20070429]
    --get [Date].[Calendar].[Date].&[20070201]
    --[Date].[Calendar].[Calendar Year].&[2007]
    --get [Date].[Calendar].[Date].&[20071001]
    --[Date].[Calendar].[Month].&[2007]&[4]
    --get [Date].[Calendar].[Date].&[20070201]
    --[Date].[Calendar].[Month].&[2007]&[5]
    --get [Date].[Calendar].[Date].&[20070301]
    --[Date].[Calendar].[Date].&[20070228]
    --get [Date].[Calendar].[Date].&[20061201]
    --[Date].[Calendar].[Date].&[20070831]
    --get [Date].[Calendar].[Date].&[20070601]
    If this does not work for you, I would suggest opening a ticket with Microsoft Support, with an advisory type of request.
    Hope this helps.
    Thanks.
    Meer Al - MSFT

  • How to calculate a week & Month in given date range (not for sele-options)

    Hi ,
      I have defined 2 date parameters in sel-screen (Plz remember that date variable are not a SELECT-OPTIONS).  Now i want ot display week nos & monts in output.
          Ex: date1: 20080101 & date2: 20080229. then
                    weeks : 1, 2, 3,---9.
                    months: jan-08, feb-08.
    Plz help me with block of code or any FM.
    Regards,

    Hi Srikanth,
            The FM HR_99S_INTERVAL_BETWEEN_DATES   is doesn't existing, but there is a fm HR_MX_INTERVAL_BETWEEN_DATES but it returns no of Years & Days.
           But i found some FM which r returns no of months for given date range. but my requirement is, want to display the month no bw 1 to 12. (ex: dat1=15-03-2008 & dat2= 01-06-2008 then in month fields 03,04,05 & 06. ).
    Plz help me on this.
    -Regards.

  • Finding the number of weeks or months in a Date range

    I have a couple of text boxes that a user inputs a start date and an end date. What I want to know is there a way to tell the number of months or the the number of days in this date range?
    For example:
    Start Date = 02/12/2004
    End Date = 03/12/2004
    The number of weeks = 4 //May not be accurate, just showing an example.
    The number of months = 2

    For month, I would define it as the dates that fall in the actual calendar month. If my start date input from the user is 1/21/04, then I want to define a time period of 1/21/04 through 1/31/04 to be included in the first month. I know that it is not an actual month, but I am trying to make graphs based on monthly performance.
    For weeks, I want the days to run Sunday through Saturday. If the first date starts on a Wednesday, then I want my first week to include days only Wednesday through Saturday.

  • Grouping by month within date range

    Hi,
    I have a date range which I like to group by months, but not from the 1st to last date of the calendar month but by given start date.  For example the table below represents the date range with some values in a table.  So the
    first month range in the group should be from 06/06/2013 to 08/07/2013.  The 06/07/2013 is absent because it's Saturday.  In fact the data is populated with working days only.  
    Table below shows what I really would like to get:
    There is a simple calculation for each month anniversary date, if the value from the start date, 06/06/2013, here 12 is less than the next month anniversary date, 08/07/2013, which is 9, then it should ignore it.  And only show the value from the month
    who's anniversary date value is less than the first date value, 12.  So the example above shows value 14 for the second month's anniversary date, 06/08/2013.  If the value has been found in any month the show, and ignore the rest. 
    I am just interested if there are any and report which number of month and the value. 
    I can implement this in procedural way, such as in VBA, but because the above looped many times it will take hours to run the process.  I have tried in SQL Server, but first problem I came up with is that I can't group by month from the given start
    date.
     Is this possible to do in T-SQL ?

    I'm not sure I entirely understand your question.  So I'll break the answer into two parts.
    First, as I understand it, you are looking for a way to group data by months, but not all dates in June, 2013 as one group, all dates in July, 2013 as the next group, etc.  Instead you want all dates from June 6, 2013 to July 5, 2013 as the first month,
    all dates from July 6, 2013 to August 5 as the second month etc.  The way to do that is use
    DATEDIFF(month, '20130606', <your date column>) + CASE WHEN DAY(<your date column>) < 6 THEN -1 ELSE 0 END
    So you can assign the month number you want to every row when you select from your table by
    SELECT DATE, VALUE, DATEDIFF(month, '20130606', DATE) + CASE WHEN DAY(DATE) < 6 THEN -1 ELSE 0 END AS MonthNumber
    FROM <your table name>
    Now as I understand it (but am not sure), you want the first value in each "month" (as you are defining "month" which is greater than the value contained in your start date and if no value in a particular month is greater than that value,
    you don't want any row for that month.  For that you could do something like
    Declare @StartDate date;
    Declare @StartValue int;
    Set @StartDate = '20130606';
    Select @StartValue = Value From <your table name>
    Where Date = @StartDate;
    ;With cteMonthNumber As
    (SELECT DATE, VALUE, DATEDIFF(month, @StartDate, DATE) + CASE WHEN DAY(DATE) < DAY(@StartDate) THEN -1 ELSE 0 END AS MonthNumber
    FROM <your table name>
    WHERE DATE > @Date AND VALUE > @Value),
    cteOrdered As
    (Select DATE, VALUE, MonthNumber,
    ROW_NUMBER() OVER (PARTITION BY MonthNumber ORDER BY DATE) As rn
    From cteMonthNumber)
    Select MonthNumber, Value As KickOutValue
    From cteOrdered
    Where rn = 1;
    Tom
    P.S.  Notice that I wrote my date literal as YYYYMMDD.  This is a good idea in SQL Server since '20130806" will always be interpreted as August 6.  But depending on the settings on your server and/or client '06/08/2013' might be dd/mm/yyyy
    and so be August 6, but it might be interpreted as mm/dd/yyyy and be June 8.
    It is also a good idea to express date literals in this forum as yyyymmdd.  There are a lot of us on the forum from the United States and we think 06/08/2013 is June 6 and a lot of us from other places who think 06/08/2013 is Aug 8.  If you give
    your dates as yyyymmdd we don't have to try to figure out what format you are using.

  • Multi-month, year, and date-range views

    My apologies for wasting everyone's time if I've missed something really obvious here, but am I correct in concluding that there is no way to generate anything beyond a static one-month view in iCal? No multi-month view? No year view? No "view date range"? At this stage of the game, how is it possible that something so elemental could be omitted from this program?
    At this point I'm reduced to exporting each month to a pdf file and then arranging them as tiles on the screen. But there has to be a better way.
    Short of a new version from Apple, are there any plug-ins that would do this? Does anyone have any other work-arounds? Thanks in advance.

    A quick search of the forums shows that this is a HIGHLY sought after feature (including by me). We all need to use the feed back link (below) to let Apple know this. In my experience with the tech support folks, they seem to have NO idea about what these forums say. In the past I have actually had them log in to these forums and search the issue I was calling them about and they have been blown away when they see the hundreds / thousands of posts with the very same thing they're discussing with me. So, as the wise man says .. "you don't ask, you don't get!" Use the form and let them know...
    http://www.apple.com/feedback/ical.html

  • Best Practice Table Creation for Multiple Customers, Weekly/Monthly Sales Data in Multiple Fields

    We have an homegrown Access database originally designed in 2000 that now has an SQL back-end.  The database has not yet been converted to a higher format such as Access 2007 since at least 2 users are still on Access 2003.  It is fine if suggestions
    will only work with Access 2007 or higher.
    I'm trying to determine if our database is the best place to do this or if we should look at another solution.  We have thousands of products each with a single identifier.  There are customers who provide us regular sales reporting for what was
    sold in a given time period -- weekly, monthly, quarterly, yearly time periods being most important.  This reporting may or may not include all of our product identifiers.  The reporting is typically based on calendar-defined timing although we have
    some customers who have their own calendars which may not align to a calendar month or calendar year so recording the time period can be helpful.
    Each customer's sales report can contain anything from 1,000-20,000 rows of products for each report.  Each customer report is different and they typically have between 4-30 columns of data for each product; headers are consistently named.  The
    product identifiers included may vary by customer and even within each report for a customer; the data in the product identifier row changes each week.  Headers include a wide variety of data such as overall on hand, overall on order, unsellable on hand,
    returns, on hand information for each location or customer grouping, sell-through units information for each location or customer grouping for that given time period, sell-through dollars information for each location or customer grouping for that given time
    period,  sell-through units information for each location or customer grouping for a cumulative time period (same thing for dollars), warehouse on hands, warehouse on orders, the customer's unique categorization of our product in their system, the customer's
    current status code for that product, and so on.
    Currently all of this data is stored in a multitude of Excel spreadsheets (by customer, division and time period).  Due to overall volume of information and number of Excel sheets, cross-referencing can take considerable time.  Is it possible to
    set-up tables for our largest customers so I can create queries and pivot tables to more quickly look at sales-related information by category, by specific product(s), by partner, by specific products or categories across partners, by specific products or
    categories across specific weeks/months/years, etc.  We do have a separate product table so only the product identifier or a junction table may be needed to pull in additional information from the product table with queries.  We do need to maintain
    the sales reporting information indefinitely.
    I welcome any suggestions, best practice or resources (books, web, etc).
    Many thanks!

    Currently all of this data is stored in a multitude of Excel spreadsheets (by customer, division and time period).  Due to overall volume of information and number of Excel sheets, cross-referencing can take considerable time.  Is it possible to
    set-up tables .....
    I assume you want to migrate to SQL Server.
    Your best course of action is to hire a professional database designer for a short period like a month.
    Once you have the database, you need to hire a professional DBA to move your current data from Access & Excel into the new SQL Server database.
    Finally you have to hire an SSRS professional to design reports for your company.
    It is also beneficial if the above professionals train your staff while building the new RDBMS.
    Certain senior SQL Server professionals may be able to do all 3 functions in one person: db design, database administration/ETL & business intelligence development (reports).
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Maybe you are looking for

  • USBOTG and Charge Simultaneo​usly on Stream 8

    To keep this thread as efficient and productive as possible for all those who it will be useful to: Unless you have in front of you 1. A schematic of the Stream 8 USB port (USB port and battery power circuit etc) 2. Source code of the BIOS firmware a

  • Need helping tracking downloads

    Hi everyone! First off I'm a complete noobie when it comes to podcasting... I've had a podcast for over a year, however, I do not know anything about coding. I use a 3rd party app called Feeder to help me with my feeds. I have a podcast in iTunes (ht

  • Unable to set the status of CSR to  "Finished",

    Hi Experts, I have a CSR. It has 8 activities. Each activities are completed. <u><b>Now when i am trying to change the status of the CSR from Followup to Finished.</b></u> its giving error. The Error is <b>"The CSR can not be finished due to open act

  • Changing an old Get URL

    Hello, I feel like I am losing my mind, and this may be a very easy fix that I am overlooking, but I am trying to just change the Get URL address of something that I did a long time ago. When I open the file, I found 2 instances where I put in the ne

  • HT5234 do i need to use a power converter to recharge my MAc in England? can a regular power coverter damage my laptop?

    do i need to use a power converter to recharge my MAc in England? can a regular power coverter damage my laptop?