Selecting missing date range with previous records value

Hello,
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SET DEFINE OFF;
create table t(NBR_OF_S number, NBR_OF_C number, S_DATE date);
Insert into  T
   (NBR_OF_S, NBR_OF_C, S_DATE)
Values
   (34, 40, TO_DATE('05/01/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into  T
   (NBR_OF_S, NBR_OF_C, S_DATE)
Values
   (27, 29, TO_DATE('03/01/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into  T
   (NBR_OF_S, NBR_OF_C, S_DATE)
Values
   (21, 23, TO_DATE('12/01/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into  T
   (NBR_OF_S, NBR_OF_C, S_DATE)
Values
   (19, 20, TO_DATE('10/01/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into  T
   (NBR_OF_S, NBR_OF_C, S_DATE)
Values
   (18, 19, TO_DATE('09/01/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into  T
   (NBR_OF_S, NBR_OF_C, S_DATE)
Values
   (17, 17, TO_DATE('08/01/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into  T
   (NBR_OF_S, NBR_OF_C, S_DATE)
Values
   (16, 16, TO_DATE('06/01/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into  T
   (NBR_OF_S, NBR_OF_C, S_DATE)
Values
   (9, 9, TO_DATE('12/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into  T
   (NBR_OF_S, NBR_OF_C, S_DATE)
Values
   (5, 5, TO_DATE('11/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into  T
   (NBR_OF_S, NBR_OF_C, S_DATE)
Values
   (2, 2, TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;
SQL> select * from t order by 3 desc;
  NBR_OF_S   NBR_OF_C S_DATE
        34         40 01-MAY-12
        27         29 01-MAR-12
        21         23 01-DEC-11
        19         20 01-OCT-11
        18         19 01-SEP-11
        17         17 01-AUG-11
        16         16 01-JUN-11
         9          9 01-DEC-10
         5          5 01-NOV-10
         2          2 01-JAN-10
10 rows selected.I want the output like as follows, all those missing date i need to carry on the last one's number
  NBR_OF_S   NBR_OF_C S_DATE
        34         40 01-MAY-12
        27         29 01-APR-12
        27         29 01-MAR-12
        21         23 01-FEB-12
        21         23 01-JAN-12
        21         23 01-DEC-11
        19         20 01-NOV-11
        19         20 01-OCT-11
        18         19 01-SEP-11
        17         17 01-AUG-11
        16         16 01-JUL-11
        16         16 01-JUN-11
         9          9 01-MAY-11
         9          9 01-APR-11
         9          9 01-MAR-11
         9          9 01-FEB-11
         9          9 01-JAN-11
         9          9 01-DEC-10
         5          5 01-NOV-10
         2          2 01-OCT-10
         2          2 01-SEP-10
         2          2 01-AUG-10
         2          2 01-JUL-10
         2          2 01-JUN-10
         2          2 01-MAY-10
         2          2 01-APR-10
         2          2 01-MAR-10
         2          2 01-FEB-10
         2          2 01-JAN-10Any help would be greatly appreciate.
Note: The date value I have created for this sample is monthly, based on the condition the data value I may need to generate weekly also. That's Monthly or weekly either one
Thanks,

And what is AMT? You didn't provide such column in your original post. Anyway, MODEL solution based on original post:
select  nbr_of_s,
        nbr_of_c,
        s_date
  from  t
  model
    partition by(rowid)
    dimension by(1 d)
    measures(
             nbr_of_s,
             nbr_of_c,
             s_date,
             months_between(lag(s_date) over(order by s_date desc),s_date) cnt
    rules(
          nbr_of_s[for d from 1 to cnt[1] increment 1] = nbr_of_s[1],
          nbr_of_c[for d from 1 to cnt[1] increment 1] = nbr_of_c[1],
            s_date[for d from 1 to cnt[1] increment 1] = add_months(s_date[1],cv(d) - 1)
  order by s_date desc
  NBR_OF_S   NBR_OF_C S_DATE   
        34         40 01-MAY-12
        27         29 01-APR-12
        27         29 01-MAR-12
        21         23 01-FEB-12
        21         23 01-JAN-12
        21         23 01-DEC-11
        19         20 01-NOV-11
        19         20 01-OCT-11
  NBR_OF_S   NBR_OF_C S_DATE   
        18         19 01-SEP-11
        17         17 01-AUG-11
        16         16 01-JUL-11
        16         16 01-JUN-11
         9          9 01-MAY-11
         9          9 01-APR-11
         9          9 01-MAR-11
         9          9 01-FEB-11
  NBR_OF_S   NBR_OF_C S_DATE   
         9          9 01-JAN-11
         9          9 01-DEC-10
         5          5 01-NOV-10
         2          2 01-OCT-10
         2          2 01-SEP-10
         2          2 01-AUG-10
         2          2 01-JUL-10
         2          2 01-JUN-10
  NBR_OF_S   NBR_OF_C S_DATE   
         2          2 01-MAY-10
         2          2 01-APR-10
         2          2 01-MAR-10
         2          2 01-FEB-10
         2          2 01-JAN-10
29 rows selected.
SQL> SY.
Edited by: Solomon Yakobson on Jun 11, 2012 1:34 PM

Similar Messages

  • How to display null values in the graphs, when i select a date range?

    Hi,
    Can you please help me in achieving the below requirement:
    We have a date promt, i have selected the date range from 12-Oct-2009 to 15-Oct-2009 and clicked on the go button.
    In the above date range, data is only availabe on 14-Oct-2009. here the requirement is to display as all the records (12th, 13th , 14th & 15th) in the bar graph.
    Currently the graph view is displaying the data only for 14-Oct-2009 in the bar graph.
    If data is not available it should display in the bar graph as empty for that particular dates.
    Help is highly apprieciated.
    Thanks in Advance.

    Check out [this post|http://obiee101.blogspot.com/2009/04/obiee-showing-zero-in-bargraph.html].

  • How to get the previous record value in the current record plz help me...

    In my sql how to get the previous record value...
    in table i m having the field called Date i want find the difference b/w 2nd record date value with first record date... plz any one help me to know this i m waiting for ur reply....
    Thanx in Advance
    with regards
    kotresh

    First of this not hte mysql or database forum so don;t repeate again.
    to get diff between two date in mysql use date_format() to convert them to date if they r not date type
    then use - (minus)to get diff.

  • Previous record values displaying in the Group Footer row in the report.

    Hi Friends,
    I have 3 tables
    TableA:(PERNR BEGDA ENDDA are key fields)
    PERNR BEGDA    ENDDA      WERKS
    10001 1/1/2010 12/31/9999 1001
    TableB:(PERNR BEGDA ENDDA SUBTY are key fields)
    PERNR BEGDA    ENDDA       SUBTY  TYPES
    10001 1/1/2010 12/31/9999   01          COMS1
    10001 1/1/2010 12/31/9999   02         COMS2
    TableC:(PERNR BEGDA  ENDDA are key fields)
    PERNR BEGDA  ENDDA        AMNT
    10001 2/2/1997 4/3/2010      1000
    10001 4/4/2010 12/31/9999  2000
    I have joined these table by the key 'PERNR'( like A->B and A->C)
    Groped by the same key 'PERNR'
    My result rows in the report:
    PERNR BEGDA    ENDDA      WERKS  SUBTY  TYPES  BEGDA    ENDDA      AMNT
    10001 1/1/2010 12/31/9999 1001       01         COMS1  2/2/1997 4/3/2010    1000
    10001 1/1/2010 12/31/9999 1001       02         COMS2  2/2/1997 4/3/2010    1000
    10001 1/1/2010 12/31/9999 1001       01         COMS1  4/4/2010 12/31/9999 2000
    10001 1/1/2010 12/31/9999 1001       02         COMS2  4/4/2010 12/31/9999 2000
    But in the report format is like this in the Group Footer row:
    PERNR: 10001                     WERKS:1001
    SUBTY: 02                          AMNT :2000 (Current date)
                                                AMNT :1000 (Previous record)
    I created the format with "Previous" function
    but in the report it is giving the '2000' instead of '1000' in the AMT field
    Please help me, can i use the for loop in the report? or any sugessions?
    Thanks in advance.
    Regards,
    Venkata

    A group footer will dis[lay contents of the last record. You need to sort records to ensure that the last record contains link to your dynamic image.
    Ian

  • How to load unicode data files with fixed records lengths?

    Hi!
    To load unicode data files with fixed records lengths (in terms of charachters and not of bytes!) using SQL*Loader manually, I found two ways:
    Alternative 1: one record per row
    SQL*Loader control file example (without POSITION, since POSITION always refers to bytes!)<br>
    LOAD DATA
    CHARACTERSET UTF8
    LENGTH SEMANTICS CHAR
    INFILE unicode.dat
    INTO TABLE STG_UNICODE
    TRUNCATE
    A CHAR(2) ,
    B CHAR(6) ,
    C CHAR(2) ,
    D CHAR(1) ,
    E CHAR(4)
    ) Datafile:
    001111112234444
    01NormalDExZWEI
    02ÄÜÖßêÊûÛxöööö
    03ÄÜÖßêÊûÛxöööö
    04üüüüüüÖÄxµôÔµ Alternative2: variable length records
    LOAD DATA
    CHARACTERSET UTF8
    LENGTH SEMANTICS CHAR
    INFILE unicode_var.dat "VAR 4"
    INTO TABLE STG_UNICODE
    TRUNCATE
    A CHAR(2) ,
    B CHAR(6) ,
    C CHAR(2) ,
    D CHAR(1) ,
    E CHAR(4)
    ) Datafile:
    001501NormalDExZWEI002702ÄÜÖßêÊûÛxöööö002604üuüüüüÖÄxµôÔµ Problems
    Implementing these two alternatives in OWB, I encounter the following problems:
    * How to specify LENGTH SEMANTICS CHAR?
    * How to suppress the POSITION definition?
    * How to define a flat file with variable length and how to specify the number of bytes containing the length definition?
    Or is there another way that can be implemented using OWB?
    Any help is appreciated!
    Thanks,
    Carsten.

    Hi Carsten
    If you need to support the LENGTH SEMANTICS CHAR clause in an external table then one option is to use the unbound external table and capture the access parameters manually. To create an unbound external table you can skip the selection of a base file in the external table wizard. Then when the external table is edited you will get an Access Parameters tab where you can define the parameters. In 11gR2 the File to Oracle external table can also add this clause via an option.
    Cheers
    David

  • XL Reporter - Selection of date range for report templates

    Dear All,
    I want to create a report using XL reporter and attach it to the main SAP B1 reports module . For this I have created the template using report composer .
    Issue:
    I have only one sub-period (ie,year wise in the posting periods)
    how i can select the date range in the Composer and attach it to the main menu.
    Regards,
    Suresh Kannan.P.

    Suresh,
                1. Goto Report Designer
                2. there u can find "Advanced Report Builder" on left side of the window
                3. At the below u can find three buttons like "Parameters", "Properties","Apply"
                4. Click on "Parameters"
                5. then Parameters window will populate
                6. Click the new Button
                7. Name: give as u like
                    Category: Literal
                    Type: Date
                    Attribute: Leave blank
                    Default Vale: Leave Blank
                    Prompt: From Date
             This is the process to create the parameters.
    create two parameters. one is fdate and ldate.

  • 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

  • Need help with select that month range with flexible first date

    Hello everyone,
    I am trying to create a selection of month range (will be in a WITH clause) for a report to display monthly data. But the first month start date can be any date. (Not necessarily the first date of the month)
    Examples:
    Report input parameters:
    Start Date: 08/10/12
    End Month: Dec 2012
    I was trying to build a with select that will list
    Month_Start, Month_End
    08/10/12, 31/10/12
    01/11/12, 30/11/12
    01/12/12, 31/12/12
    OR
    Month_Start, Next_Month
    08/10/12, 01/11/12
    01/11/12, 01/12/12
    01/12/12, 01/01/13
    End month is optional, so if no value the select will list only
    08/10/12, 01/11/12
    Oracle Database Details is
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    My code so far is
    VARIABLE  P50_START_DATE  VARCHAR2 (10)
    VARIABLE  P50_END_MONTH    VARCHAR2 (10)
    EXEC  :P50_START_DATE  := '10/10/2012';
    EXEC  :P50_END_MONTH   := '31/12/2012';
      SELECT  to_char(:P50_START_DATE) AS start_date
            ,  ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), 1) AS next_month
      FROM dual
      union
       SELECT to_char(ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), ROWNUM-1)) AS start_date
       ,      ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), ROWNUM) AS next_month
       --, rownum
       from all_objects
       where
       rownum <= months_between(to_date(NVL(:P50_END_MONTH, :P50_START_DATE),'DD/MM/YYYY'), add_months(to_date(:P50_START_DATE,'DD/MM/YYYY'), -1))
       and rownum > 1If I put comment – on line and rownum > 1, as
    -- and rownum > 1The result I get is
    START_DATE                     NEXT_MONTH               
    01/10/12                       01/10/12                 
    01/11/12                       01/11/12                 
    01/12/12                       01/01/13                 
    10/10/2012                     01/11/12    But when I try to remove the duplicate period (of the first month) out by restrict rownum, it do not return any rows for the second select at all. The result I get is:
    START_DATE                     NEXT_MONTH               
    10/10/2012                     01/11/12    Can anyone advise what wrong with the select statement ?
    Thanks a lot in advance,
    Ann

    Hi,
    Here's one way:
    WITH   params      AS
         SELECT     TO_DATE (:p50_start_date, 'DD/MM/YYYY')     AS start_date
         ,     TO_DATE (:p50_end_month,  'DD/MM/YYYY')     AS end_date
         FROM     dual
    SELECT     GREATEST ( start_date
               , ADD_MONTHS ( TRUNC (start_date, 'MONTH')
                            , LEVEL - 1
              )               AS month_start
    ,     LEAST     ( end_date
              , ADD_MONTHS ( TRUNC (start_date, 'MONTH')
                          , LEVEL
                        ) - 1
              )               AS month_end
    FROM    params
    CONNECT BY     LEVEL     <= 1 + MONTHS_BETWEEN ( end_date
                                      , TRUNC (start_date, 'MONTH')
    ;:p50_end_month doesn't have to be the last day of the month; any day will work.
    If you want to generate a Counter Table containing the integers 1 througn x in SQL, you could say
    SELECT  ROWNUM  AS n
    FROM    all_objects
    WHERE   ROWNUM  <= x
    ;but, starting in Oracle 9.1, it's much faster to say
    SELECT  LEVEL   AS n
    FROM    dual    -- or any table containing exactly 1 row
    CONNECT BY  LEVEL <= x
    ;Also, x can be greater than the number of rows in all_objects.

  • Date Picker with Previous and Next Year Options

    Hi All,
    I am implementing a date picker in my application which is tied to an attribute of type PA0001-BEGDA. Date Picker as such works fine but navigating to previous year and Next year options are not available. User has to go month by month to different years if they have to navigate.
    Is this the normal behavior of the Date Picker or am I missing something else to get the previous and Next year icons in the Date Picker.
    Thanks,
    Nagarajan.

    hmm..I tried using the select options and it did give the same date picker with the previous and Next navigation icons...The only problem with the select options is that its a single field which has the range and can accept multiple values too...
    I tried to figure out how the date picker that we use in the custom application and the one in Select Options differ but no luck...Does this ring any bell?
    Thanks,
    Nagarajan.

  • Compute Date Range with SQL Statement

    I'm sure there is a way to do this in SQL, but I cannot figure it out. I can write a PL/SQL script to do it, but would prefer using a SQL Statement. My database is Oracle Database 10.2.0.4.0.
    I have a table that contains information such as the employee number, department id, and the effective date of when the person started in that department. There is data in another table that I want to update their department number in based on their effective date range. If I could figure out how to select the effective date range correctly, I can do the rest.
    I have data such as:
    EMP_ID DEPT_NO EFFECTIVE
    101 1000 1/15/2001
    101 1050 5/24/2005
    101 2010 6/8/2008
    101 1000 8/2/2010
    I want to write a SELECT statement that returns something like this where the END_DATE is the day before the EFFECTIVE date and the last record does not have an END_DATE because they are still assigned to that department. Also, the first record in the column, I don't want to select a DEPT_NO because the effective date logic was added in January 2001 so if a person started back in 1985 they could have switched departments zero to many times so I'm not going to update any data for that period:
    EMP_ID DEPT_NO EFFECTIVE END_DATE
    101 1/14/2001
    101 1000 1/15/2001 5/23/2005
    101 1050 5/24/2005 6/7/2008
    101 2010 6/8/2008 8/1/2010
    101 1000 8/2/2010
    Below is a script to create the data in a temp table that can be used to write a SELECT statement on. I have added two employee records with different dates.
    create table temp_activity
    (emp_id number(12),
    dept_no number(12),
    effective date);
    INSERT INTO temp_activity
    (EMP_ID,DEPT_NO,EFFECTIVE)
    VALUES
    (101,1000,to_date('1/15/2001','MM/DD/YYYY'))
    INSERT INTO temp_activity
    (EMP_ID,DEPT_NO,EFFECTIVE)
    VALUES
    (101,1050,to_date('5/24/2005','MM/DD/YYYY'))
    INSERT INTO temp_activity
    (EMP_ID,DEPT_NO,EFFECTIVE)
    VALUES
    (101,2010,to_date('6/8/2008','MM/DD/YYYY'))
    INSERT INTO temp_activity
    (EMP_ID,DEPT_NO,EFFECTIVE)
    VALUES
    (101,1000,to_date('8/2/2010','MM/DD/YYYY'))
    INSERT INTO temp_activity
    (EMP_ID,DEPT_NO,EFFECTIVE)
    VALUES
    (102,1040,to_date('1/15/2001','MM/DD/YYYY'))
    INSERT INTO temp_activity
    (EMP_ID,DEPT_NO,EFFECTIVE)
    VALUES
    (102,2000,to_date('6/16/2006','MM/DD/YYYY'))
    Any help is appreciated. This is probably easy, but I cannot get my brain wrapped around it.
    Thanks - mike

    select  emp_id,
            dept_no,
            effective,
            end_date
      from  (
              select  emp_id,
                      dept_no,
                      effective,
                      lead(effective) over(partition by emp_id order by effective) - 1 end_date,
                      row_number() over(partition by emp_id order by effective) rn
                from  temp_activity
             union all
              select  emp_id,
                      null dept_no,
                      null effective,
                      min(effective) - 1 end_date,
                      0 rn
                from  temp_activity
                group by emp_id
      order by emp_id,
               rn
        EMP_ID    DEPT_NO EFFECTIVE  END_DATE
           101                       01/14/2001
           101       1000 01/15/2001 05/23/2005
           101       1050 05/24/2005 06/07/2008
           101       2010 06/08/2008 08/01/2010
           101       1000 08/02/2010
           102                       01/14/2001
           102       1040 01/15/2001 06/15/2006
           102       2000 06/16/2006
    8 rows selected.
    SQL> SY.

  • Predefined Date Ranges as List of Values in Webi Prompt

    Hi All
    We have a Webi report that has a custom object "Date End" (BW tech name ZDATE_END referencing 0DATE).  Users would like to see in the prompt's List of Values predefined date ranges.
    In other words, when the report is executed, for that "Date End" prompt, 2 options should appear in the List of Values:
    Current
    1 Year
    whereby-
    "Current" has been predefined as any "Date End" in the range (Current Day) to (31.12.9999)
    "1 Year"  is any "Date End" in the range (Current day -365) to (Current Day -1)
    I suspect I need to create a Filter condition on the "Date End" object in the Universe Designer and I have been trying with the different operators and prompt settings, etc but I am not getting it right.  The parsing is OK, but the filter is not happening in Webi and the report is bring back all records.
    Can anyone please assist with how to create such conditions in the Designer (steps, syntax, etc) ?
    We are using SAP BW 7 and Webi XI 3.1 and run on a DB2 database.
    Thanks in advance
    Anton
    Edited by: Anton Vogel on Jul 20, 2011 10:52 AM
    Edited by: Anton Vogel on Jul 20, 2011 12:11 PM

    Hi All
    We have a Webi report that has a custom object "Date End" (BW tech name ZDATE_END referencing 0DATE).  Users would like to see in the prompt's List of Values predefined date ranges.
    In other words, when the report is executed, for that "Date End" prompt, 2 options should appear in the List of Values:
    Current
    1 Year
    whereby-
    "Current" has been predefined as any "Date End" in the range (Current Day) to (31.12.9999)
    "1 Year"  is any "Date End" in the range (Current day -365) to (Current Day -1)
    I suspect I need to create a Filter condition on the "Date End" object in the Universe Designer and I have been trying with the different operators and prompt settings, etc but I am not getting it right.  The parsing is OK, but the filter is not happening in Webi and the report is bring back all records.
    Can anyone please assist with how to create such conditions in the Designer (steps, syntax, etc) ?
    We are using SAP BW 7 and Webi XI 3.1 and run on a DB2 database.
    Thanks in advance
    Anton
    Edited by: Anton Vogel on Jul 20, 2011 10:52 AM
    Edited by: Anton Vogel on Jul 20, 2011 12:11 PM

  • Date Ranges with EOMONTH

    Hi I'm look
    for a date ranges query, any help would be greatly appreciated<o:p></o:p>
    Ie
    01/06/2014 to 30/06/2014<o:p></o:p>
    SELECT
    count(DISTINCT[Form Number]) as OutofFunding
    FROM [dbo].[NEWVIEW]
    WHERE [Cohort Desc] IN ('Apprenticeships')
    AND [Expected End] > EOMONTH(GETDATE(), -1) <o:p></o:p>

    Here is how you can do datetime range with EOMONTH:
    SELECT Count(DISTINCT[form number]) AS OutofFunding
    FROM [dbo].[newview]
    WHERE [cohort desc] IN ( 'Apprenticeships' )
    AND [expected end] > Eomonth(Getdate(), -1)
    AND [expected end] < Dateadd(dd, 1, Eomonth(Getdate(), 4));
    BLOG on datetime ranges:
    http://www.sqlusa.com/bestpractices2008/between-dates/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Select multiple date ranges?

    I am looking to select from a set of date ranges. I know that a UNION will work, but how to I get a valid set of results from multiple dates without a UNION?
    example:
    select date from test
    where date >= '01-MAR-07 0000'
    and date <= '02-MAR-07 0000'
    and date >= '04-MAR-07 0000'
    and date <= '08-MAR-07 0000'
    order by date;
    This gets zero records.
    But if I use UNION:
    select date from test
    where date >= '01-MAR-07 0000'
    and date <= '02-MAR-07 0000'
    union
    select datre from test
    and date >= '04-MAR-07 0000'
    and date <= '08-MAR-07 0000'
    order by date;
    It works, I get the records in no test table.
    How can I structure this query to work without UNION?

    true, date is taken eh?
    I am still running into an issue:
    Let's say I am using the following context:
    select date1, name from test
    where name in ('SUNDAR', 'ASUNDAR')
    and date1 >= '01-MAR-07 0000'
    and date1 <= '03-MAR-07 0000'
    or (date1 >= '05-MAR-07 0000'
    and date1 <= 07-MAR-07 0000');
    My results are wrong, it would not include the select as part of the or clause.

  • Display date range with given week no

    Can anyone please suggest on how to display Date range when wek no is given in APEX 4.0.2?
    Example: given week no as 20 then I need to show week_start_date as 7/18/2011 and week_end_date as 7/25/2011 .
    Thanks

    maybe this could help you on the way to a solution:
    with dates as
        ( select dat, to_char(dat+1, 'iw') week
        from (select to_date('01-01-2011', 'DD-MM-YYYY') + rownum dat
        from all_objects)
        where rownum < 1000)
    select week, min(dat), max(dat)
    from dates
    where week = 20
    group by week
    order by week;You have to check which format for week you want to use: WW (first week starts at the 1st of January) IW (ISO week number)
    see also: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:7482139067917

  • Date ranges with OLE DB

    Post Author: georgeb
    CA Forum: Data Connectivity and SQL
    Does anyone know if the issue with date ranges in OLE DB reports using Visual Foxpro databases has been resolved in Crystal Reports 10?
    Currently all OLE DB reports that use date ranges crash with:
    Failed to open a rowset.Details: ADO Error Code: 0x80004005Source: Microsoft OLE DB Provider for Visual FoxProDescription: SQL: Column 'DATETIME' is not foundNative Error: 806We referred this to Business Objects some time ago and their comment was that they do not supportVisual FoxPro ...
    Any assistance would be appreciated.

    Here is how you can do datetime range with EOMONTH:
    SELECT Count(DISTINCT[form number]) AS OutofFunding
    FROM [dbo].[newview]
    WHERE [cohort desc] IN ( 'Apprenticeships' )
    AND [expected end] > Eomonth(Getdate(), -1)
    AND [expected end] < Dateadd(dd, 1, Eomonth(Getdate(), 4));
    BLOG on datetime ranges:
    http://www.sqlusa.com/bestpractices2008/between-dates/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Maybe you are looking for