Return rows where date between sysdate +- 2 years

Hi,
Please let me know how to select rows from table where date = sysdate +- 2 years
if sysdate is 27/07/2012 then select rows where date between 27/07/2010 to 27/07/2014

you need all date ? or only specific date ?
Specific date Purvesh already provided solution
All
SELECT * FROM ( SELECT SYSDATE+LEVEL AFTER,SYSDATE-LEVEL befor FROM dual connect BY LEVEL<=365*2 )Or specific
SELECT Max(AFTER),Min(befor) FROM
( SELECT SYSDATE+LEVEL AFTER,SYSDATE-LEVEL befor FROM dual connect BY LEVEL<=365*2 )

Similar Messages

  • Date between sysdate-50 and sysdate  problem

    hi,
    i have a big big problem and i need some help
    I have oracle 8i and 10g databases installed at work. i have a problem with an select statement that brings data from 3 tables.
    The select looks like this:
    select mms_id, img_id, mms_usr_id as usr_id, mms_pvd_id, mms_data as data
    from vsc_mms vm, vsc_image vi, vsc_user vu
         where img_mms_id = mms_id
         and mms_usr_id = usr_id and usr_client_id = cli
         and img_mms_id <> 0
              and mms_status =0
              and mms_data between data_ini and data_end .......is not very important; the joins are made all right. What is important is that:
    vsc_mms has aprox. 3.000.000 recordings
    vsc_image has, also, aprox. 3.000.000 recordings.
    select count(distinct img_date) from vsc_image =657.021
    select count(distinct mms_data) from vsc_mms >=600.000
    On both tables there are, among other, index on mms_data, img_date.
    Now, my data_ini and data_end come from java (user send data_ini and data_end through http:// ) OR i can put this select in a procedure like:
    declare
    datai date:=to_date('20.01.2006','dd.mm.yyyy');
    datae date:=to_date('30.01.2006','dd.mm.yyyy');
    ......my select ..... and mms_data between data_ini and data_end
    the select takes on 8i more than 30 seconds. the same select takes on 10G quite same long time. i also run the select using
    and mms_data between sysdate-50 and sysdate and i got the same long time.
    Also important: this select brings almost 30 recordings; when the restrictions are too severe and the count(*) =0 the result is brought in 0.01 seconds; outherwise, when count(*) >1, is ruinous.
    But, if i put and mms_data between to_date('20.01.2006','dd.mm.yyyy') and to_date('30.01.2006','dd.mm.yyyy'), the response come in 1 seconds or less.
    1. Can someone help me and tell me why i got this long time for response when i use sysdate or when receiving data_ini, data_end like parameters from java
    2. is it true that for a better usage of a index, the procent of repeatedly recordings has to be small? I mean when i have 600.000 distinct recordings from 3.000.000 is it good or not to use index on that column?
    thanks in advance

    There can be some difference in how Oracle builds execution plan when
    you are using binding variables and explicit values:
    SQL> create index idxtbl1 on tbl1(date#);
    Index created.
    SQL> insert into tbl1 select sysdate-rownum from (select 1 from dual connect by lev
    200000 rows created.
    SQL> create index idxtbl1 on tbl1(date#);
    Index created.
    SQL> analyze table tbl1 compute statistics for all indexes;
    Table analyzed.
    SQL>set autotrace traceonly
    SQL> var a1 varchar2(20)
    SQL> var a2 varchar2(20)
    SQL> select * from tbl1 where date# between to_date('01/01/1900','dd/mm/yyyy')
      2  and to_date('01/01/1901','dd/mm/yyyy');
    365 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=365 Bytes=3
              285)
       1    0   INDEX (RANGE SCAN) OF 'IDXTBL1' (INDEX) (Cost=3 Card=365 B
              ytes=3285)
    Statistics
              0  recursive calls
              0  db block gets
             28  consistent gets
              0  physical reads
              0  redo size
           6809  bytes sent via SQL*Net to client
            772  bytes received via SQL*Net from client
             26  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            365  rows processed
    SQL> exec :a1 := '01/01/1900'
    PL/SQL procedure successfully completed.
    SQL> exec :a2 := '01/01/1901'
    PL/SQL procedure successfully completed.
    SQL> select * from tbl1 where date# between to_date(:a1,'dd/mm/yyyy')
      2  and to_date(:a2,'dd/mm/yyyy');
    365 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=4 Card=495 Bytes=4
              455)
       1    0   FILTER
       2    1     INDEX (RANGE SCAN) OF 'IDXTBL1' (INDEX) (Cost=4 Card=495
               Bytes=4455)
    Statistics
              0  recursive calls
              0  db block gets
             28  consistent gets
              0  physical reads
              0  redo size
           6809  bytes sent via SQL*Net to client
            772  bytes received via SQL*Net from client
             26  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            365  rows processedRgds.

  • Auto Counting Number of Rows Where Data is Entered

    I am trying to automatically count the number of rows where data is entered.  For example, I have a table with six open rows to enter information.  If only three of those rows (A2-A4) had names entered in them, and the next three rows were left blank, can I get each name to equal the value "1" so that I can get a total tally of how many names have been entered? So the final tally in this example would be "3." I appreciate your help!
    file:///Users/josephdlugo/Desktop/Screen%20Shot%202014-04-30%20at%2011.58.28%20A M.png

    there is a function, COUNTA(), that will count the number of items that are not empty:
    C1=COUNTA(B)
    this is shorthand for select cell C1, then type, or copy and paste the formula:
    =COUNTA(B)
    The COUNTA function returns the number of its arguments that are not empty.
    COUNTA(value, value…)
    value: Any value or a collectioncontaining any values.
    value…: Optionally include one or more additional values or collections.

  • SDO_RELATE to return rows where point is in polygon

    Is it possible to return rows from a table where an input point geometry falls within the polygon sdo_geometry column stored in the row? I don't just want to return the geometry, but all columns in the row where the geometry "intersects".
    I'm trying this, but run into an error:
    SELECT * FROM COUNTY_PARCEL R where SDO_RELATE(R.SHAPE, MDSYS.SDO_GEOMETRY(2001,2868,MDSYS.SDO_POINT_TYPE(656849.49,883088.84,NULL),NULL,NULL), 'mask=anyinteract') = 'TRUE'
    ORA-29902: error in executing ODCIIndexStart() routine
    ORA-13282: failure on initialization of coordinate transformation
    ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 286
    Any help is much appreciated.
    Edited by: user12167574 on Feb 25, 2010 3:10 PM

    Guddie
    YOUR SQL as such should do what you have described, however, the error message "ORA-13282: failure on initialization of coordinate transformation" is indicating an issue with coord transformation.
    from the user manual:
    "If geometry1 and geometry2 are based on different coordinate systems, geometry2 is temporarily transformed to the coordinate system of geometry1 for the operation to be performed, as described in Section 6.10.1."
    could it be that the COUNTY_PARCEL table geometries have a different SRID then 2868 (from your input point geometry)?
    might it even be so, that the COUNTY_PARCEL have no srid set?
    Can you check that and let us know?
    tx
    Luc

  • How to return rows where count = 0

    Hi, I have the below query that returns the quarters along with the number of issues:
    select MQTR as Quarter, count(MQTR)
    from tbl1, tbl2
    where Fdate=Cdate
    and cycle_missed = 'Yes'
    group by MQTR
    order by 1
    output:
    2006-Q2      1
    2006-Q3      1
    2007-Q2      2
    I know that 2007-Q1 has 0 issues but I can't get the query to return the row with count 0. So my question is how I can get this output:
    2006-Q2      1
    2006-Q3      1
    2007-Q1      0
    2007-Q2      2

    SQL> create table tbl1
      2  as
      3  select date '2006-04-10' cdate, '2006-Q3' mqtr from dual union all
      4  select date '2006-08-11', '2006-Q4' from dual union all
      5  select date '2006-10-12', '2007-Q1' from dual union all
      6  select date '2007-02-13', '2007-Q2' from dual
      7  /
    Tabel is aangemaakt.
    SQL> create table tbl2
      2  as
      3  select date '2006-04-10' run_date, 'Yes' interventions from dual union all
      4  select date '2006-04-15', 'Yes' from dual union all
      5  select date '2006-08-19', 'No' from dual union all
      6  select date '2006-10-20', 'Yes' from dual union all
      7  select date '2006-12-20', 'No' from dual union all
      8  select date '2007-02-20', 'No' from dual
      9  /
    Tabel is aangemaakt.
    SQL> select tbl1.mqtr
      2       , count(tbl2.run_date) "Count"
      3    from tbl1
      4       , tbl2
      5   where tbl1.mqtr = to_char(add_months(tbl2.run_date (+),3),'yyyy-"Q"q')
      6     and tbl2.interventions (+) = 'Yes'
      7   group by mqtr
      8   order by mqtr
      9  /
    MQTR         Count
    2006-Q3          2
    2006-Q4          0
    2007-Q1          1
    2007-Q2          0
    4 rijen zijn geselecteerd.Regards,
    Rob.

  • Select where timestamp between date1 and date 2

    try a lot of variations but still dont work
    this was my last shot, then i come here ask for help
    the field DATAHORAS is timestamp
    data1 and dat2 will come from a form
    To_Date(S.DATAHORAS, 'dd/mm/yyyy hh24:mi:ss')
    Between Cast(To_Date(:data1) As TimeStamp) And Cast(To_Date(:data2) As TimeStamp)
    thanks in advanced

    No. You don't need to. But....
    Edit: I was originally using a stupid example using DUAL which was completely misleading - sorry.
    Originally I used the example below to show that you don't have to do an explicit conversion.
    Things will still work comparing timestamps and dates.
    SQL> select systimestamp, sysdate, sysdate+1
      2  from dual
      3  where systimestamp between sysdate and sysdate + 1;
    SYSTIMESTAMP                        SYSDATE              SYSDATE+1
    09-FEB-10 13.58.35.712017 +00:00    09-FEB-2010 13:58:35 10-FEB-2010 13:58:35But then I added an explain plan to show that implicit conversions were going on:
    1  explain plan for
      2  select systimestamp, sysdate, sysdate+1
      3  from dual
      4* where systimestamp between sysdate and sysdate + 1
    SQL> /
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 4192335797
    | Id  | Operation        | Name              | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |                   |     1 |     1   (0)| 00:00:01 |
    |*  1 |  FILTER          |                   |       |            |          |
    |   2 |   INDEX FULL SCAN| SYS_IOT_TOP_57625 |     1 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       1 - filter(SYS_EXTRACT_UTC(SYSTIMESTAMP(6))<=SYS_EXTRACT_UTC(SYSDATE@
                  !+1) AND SYS_EXTRACT_UTC(SYSTIMESTAMP(6))>=SYS_EXTRACT_UTC(SYSDATE@!))
    15 rows selected.
    SQL>However, this example is misleading because it's not the same implicit conversion you get with a proper table with a timestamp column:
    SQL> create table t1
      2  (col1 timestamp);
    Table created.
    SQL> ed
    Wrote file afiedt.buf
      1   explain plan
      2   for
      3   select *
      4   from   t1
      5   where col1 between to_date('08-JAN-2010','DD-MON-YYYY')
      6*             and     to_date('09-JAN-2010','DD-MON-YYYY')
    SQL> /
    Explained.
    SQL>
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3617692013
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     1 |    13 |     2   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| T1   |     1 |    13 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       1 - filter("COL1">=TIMESTAMP' 2010-01-08 00:00:00' AND
                  "COL1"<=TIMESTAMP' 2010-01-09 00:00:00')
    Note
       - dynamic sampling used for this statement
    18 rows selected.
    SQL>Which is really what you want.
    It has an implicit conversion on the date parameters and no implicit conversion on the column which would prevent index usage if there were an index.
    Interestingly if you explicitly convert the dates to a timestamp, then you can get an extra filter predicate comparing the two parameters:
    SQL> explain plan
      2  for
      3  select *
      4  from   t1
      5  where col1 between cast(to_date('08-JAN-2010','DD-MON-YYYY') as timestamp)
      6             and     cast(to_date('09-JAN-2010','DD-MON-YYYY') as timestamp);
    Explained.
    SQL>
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3332582666
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |    13 |     2   (0)| 00:00:01 |
    |*  1 |  FILTER            |      |       |       |            |          |
    |*  2 |   TABLE ACCESS FULL| T1   |     1 |    13 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       1 - filter(CAST(TO_DATE(' 2010-01-08 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AS timestamp)<=CAST(TO_DATE(' 2010-01-09 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss') AS timestamp))
       2 - filter("COL1">=CAST(TO_DATE(' 2010-01-08 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AS timestamp) AND "COL1"<=CAST(TO_DATE(' 2010-01-09
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss') AS timestamp))
    Note
    PLAN_TABLE_OUTPUT
       - dynamic sampling used for this statement
    23 rows selected.oracle version 11.1.0.6
    Sorry about the mistakes in previous version of this reply.
    Edited by: DomBrooks on Feb 9, 2010 2:25 PM

  • How to compare table's date field with dropdown year field

    Hi All,
    I have one requirement to display the selected rows from a database table based on the selection of drop down.
    Here, I have one dropdown of year(like 2009,2010,....) and I have one database table which contains one field with "DATE".
    Now, I want to compare table's DATE field with my dropdown field.
    Problem is that table's DATE field is of type "DATS" and dropdown is of type INTEGER(or) STRING ...
    How to compare this fields?
    Can any one please give me solution for this...!
    Thanks in Advance!

    Hi  sreelakshmi.B,
    try the following:
    DATA lt_dats        TYPE TABLE OF dats.
    DATA l_dat_i        TYPE          i.
    DATA l_dat_c_4(4)   TYPE          c.
    DATA l_dat_c_12(12) TYPE          c.
    DATA l_dats_from    TYPE          dats.
    DATA l_dats_to      TYPE          dats.
    *Move Date from Integer to Char
    l_dat_c_4 = l_dat_i = 2005.
    *Create Date From use in WHERE-Clause
    CONCATENATE '01.01.' l_dat_c_4 INTO l_dat_c_12.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
         EXPORTING
              date_external            = l_dat_c_12
         IMPORTING
              date_internal            = l_dats_from
         EXCEPTIONS
              date_external_is_invalid = 1
              OTHERS                   = 2.
    IF sy-subrc <> 0.
    ENDIF.
    *Create Date To use in WHERE-Clause
    CONCATENATE '31.12.' l_dat_c_4 INTO l_dat_c_12.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
         EXPORTING
              date_external            = l_dat_c_12
         IMPORTING
              date_internal            = l_dats_to
         EXCEPTIONS
              date_external_is_invalid = 1
              OTHERS                   = 2.
    IF sy-subrc <> 0.
    ENDIF.
    * Select records in range
    SELECT *
           FROM [DBTAB]
           INTO TABLE [ITAB]
           WHERE [DATE] BETWEEN l_dats_from
                        AND     l_dats_to.
    Regards
    REA

  • Display all dates between date range (Time Dimension left outer join Fact)

    All,
    I have done some searching around this issue but within all the posts regarding date variables, date prompts and date filtering I haven't seen one exactly answering my issue (maybe they are and I just dont have my head around it correctly yet).
    My report requirement is to allow a user to select a start day and an end day. The report should show all activity between those two days - AND display 0/null on days where there is no activity. That second part is where I am getting hung up.
    The tables in question are:
    TimeDim
    EventFact
    CustomerDim
    My BMM is setup as follows:
    TimeDim left outer join EventFact
    CustomerDim inner join EventFact
    If I run a report selecting DAY from TimeDim and a measure1 from EventFact with day range 1/1/2010 - 12/31/2010 .. I get a record for every day and it looks perfect because of the left outer join between TimeDim and CustomerDim.
    But .. if I add in a field from CustomerDim, select TimeDim.DAY, CustomerDim.CUSTNAME, EventFact.MEASURE1, OBIEE only returns records for the days that have EventFact records.
    This is due to the fact that the TimeDim is still outer joined into EventFact but adding in CustomerDim makes OBIEE setup an inner join between those tables which then causes only data to be returned where EventFact data exists.
    There is a way around this in this simple case and that is to define the relationship between CustomerDim and EventFact as an outer join as well. This will give the desired effect (but an outer join between these two tables is not the true relationship) and as I add additional dimensions and add additional logical sources to a single dimension in the BMM it gets complicated and messy.
    Ive also messed with setting the driving table in the relationship, etc.. but it has not given the desired effect.
    Has anyone ever encountered the need to force display all dates within a specfied range with a fact table that may not have an entry for every date?
    Thanks in advance.
    K
    Edited by: user_K on Apr 27, 2010 11:32 AM

    It worked!!!* Even my time drill downs and date based filtering still work!
    That is awesome. Never would have thought of that intuitively.
    Now, just need a little help understanding how it works. When I run my report and check the logs I can see that two queries are issued:
    Query 1: Joins the fact table to all the associated dimensions. I even changed all the relationships to inner joins (which is what they truly are). And calculates the original measure. If I copy and paste this query into sql developer it runs fine but only returns those rows that joined to the time dimension - which is what was happening before. It is correct but I wanted a record for every time dimension record.
    Query 2: Looks like the following:
    select sum(0)
    from timedim
    where date between <dateprompt1> and <dateprompt2>
    group by month *<--* this is the time dimension level specified in Query 1, so it knows to aggregate to the month level as was done in query 1
    Final Question: So what is OBIEE doing ultimately, does it issue these two requests and then perform a full outer join or something to bring them together? I couldn't see anywhere in the log a complete query that I could just run to see a similar result that I was getting in Answers.
    Thanks for all the help .. Id give more points if I could.
    K

  • 30EA1: Database mounted, can't get rows with DATEs

    I'm starting to use SQL Developer 3.0.02 build MAIN-02.37. I tried to use it with a 10g standby database that is only mounted, to check on its recovery progress, and it appears to NOT return rows with DATE columns in them. I've tried this with both a TNS connection and a basic connection. If the database is open, no problem.
    Example: select instance_name, host_name, startup_time from v$instance;
    If I remove the DATE column "startup_time" from the query, I get the expected rows. The Logging Page pane at the bottom shows ORA-01219 errors "database not open, queries allowed on fixed tables/views only."
    I get that ORA-01219 message in TOAD against the mounted standby database, but I also get all the rows including the DATE column when I run the exact same statement there.
    Is this a bug, or expected behaviour, or is there some setting I'm missing?
    Edited by: gmaccrim on Nov 25, 2010 4:26 PM

    I have similar problem on standby database with query on v$database.
    This query
    SELECT name,dbid FROM V$database
    works fine, but this one
    SELECT name,dbid,created FROM V$database
    doesn't return any row.
    I have Version 2.1.1.64 Build MAIN-64.45.

  • Stored Procedure/Function Returns Rows?

    Hello,
    I have very little experience writing PL/SQL procedures, but I have written my fair share of Sybase stored procedures. In Sybase, I can create a stored procedure that returns rows of data. For example:
    create procedure myproc as
    begin
    select * from mytable;
    end;
    Then if I invoke the procedure (whether that is from an interactive SQL session or from a ColdFusion or JSP page), several rows of data are returned to me.
    The benefit of this is that the web developers don't need to write complicated SQL.
    Is this even possible in Oracle? I have never seen anyone actually do this. Or do my web coders need to learn how to write PL/SQL and embed it into their code?
    HELP!
    Thanks!

    Hi Justin,
    Thanks for your reply. That's kind of what I was suspecting, except that I was hoping to be able to execute the function/procedure from within a SQL session also, for testing. Is there a way to invoke such a procedure from a SQL*Plus session and have it return the rowset (ref cursor) just as if I had typed in the SQL select statement?
    For example, I just want to type at a SQL*Plus prompt something like this:
    mypackage.myfunction(param1, param2);
    and then have it return the results to me. Is that possible?
    Thanks again for your help.
    Mark

  • Find to find date between 05/01/2003 and 05/29/2003

    Indeed, it's something about sql...
    I write a programme to have query on access database
    I try to
    sql="select * from PO where Date between to_date('05012003','mmddyyyy') and to_date('05292003','mmddyyyy')";
    but it's doesn't work...why?no (to_date) function in access??
    pls help!!

    When you are going through java to any database it uses a third party bridge that converts the SQL statements into something that the target database understands. Some of these third party bridges only conform to true SQL statements. Best to find out how the bridge functions.
    As such Java supports the ANSI SQL-2 standard.
    I imagine others will correct any errors in my statement, but I belive my answer is esentially right. Of course the jist of it is that you are going to have to find out how the particular bridge you are using handles date manipulations, It has little to nothing to do with the underlying database and everything to do with the connection bridge software.

  • Return rows when there is a certain difference between dates

    Hello.
    I have table called
    #president#
    pres_name
    birth_date
    and
    #winner#
    name
    year_elected
    I would like to have all presidents returned, who where under the age 50 when they where elected.
    year_elected is only a 4 digit number; 1924 etc while birth_date is 2001-01-01 etc.
    I have no idea how to make this work, ive tried substr and alot of other weird (and prob wrong) stuff.
    select distinct p.pres_name, substr(p.birth_date, 0, 4), w.year_elected
    from president p, winner w
    where p.pres_name = w.nameI did this query witch will show me all presidents, and their dates of election and date of birth. Now i just want something that only returns the guys where its a 49 (?) value difference between birth_date and year_elected
    Johan
    Edited by: user10248089 on 2008-okt-02 00:42

    Based on Dave's information about presidents being elected on first Tuesday in Nov...
    SQL> with president as (select 'Bob' as pres_name, to_date('1/7/1934','DD/MM/YYYY') as birth_date from dual union all
      2                     select 'Fred', to_date('13/5/1950','DD/MM/YYYY') from dual union all
      3                     select 'Jim', to_date('21/12/1960','DD/MM/YYYY') from dual)
      4      ,winner    as (select 'Bob' as name, '1979' as year_elected from dual union all
      5                     select 'Fred', '2005' from dual union all
      6                     select 'Jim', '2000' from dual)
      7  --
      8  select p.pres_name, p.birth_date, w.year_elected
      9        ,trunc(months_between(next_day(to_date('01/11/'||w.year_elected,'DD/MM/YYYY'),'TUE'),birth_date)/12) as age
    10  from president p join winner w on (p.pres_name = w.name)
    11  /
    PRES BIRTH_DAT YEAR        AGE
    Bob  01-JUL-34 1979         45
    Fred 13-MAY-50 2005         55
    Jim  21-DEC-60 2000         39
    SQL>And the WHERE clause can be applied based on the same calculation as shown in the age column

  • When ever  enter the date start date up to next year same date between the days divided into 8 parts

    when ever  enter the date start date up to next year same date between the days divided into 8 parts
    Q1.1 (YYYY) = 1st half of Quarter 1 for year YYYY
    Q1.2 (YYYY) = 2nd half of Quarter1 for year YYYY
    Q2.1 (YYYY) = 1st half of Quarter 2 for year YYYY
    Q2.2 (YYYY) = 2nd half of Quarter 2 for year YYYY
    Q3.1 (YYYY) = 1st half of Quarter 3 for year YYYY
    Q3.2 (YYYY) = 2nd half of QuarterQ3 for year YYYY
    Q4.1 (YYYY) = 1st half of Quarter 4 for year YYYY
    Q4.2 (YYYY) = 2nd half of Quarter 4 for year YYYY
    Here YYYY depicts the year.
    e.g. Q1.2 (2014) depicts the 2nd half of Quarter 1 for year 2014.
    The description of these values are explained below.
    The table below provides the description about each value:
    Quarter     Quarter Range      Start Date
    Q1.1      1 Jan - 15 Feb         1st  Jan
    Q1.2      16 Feb-31 Mar         16th Feb
    Q2.1      1 Apr- 15 May          1st Apr
    Q2.2      16 May-30 June       16th May
    Q3.1      1 Jul-15 Aug             1th Jul
    Q3.2      16 Aug -30 Sep       16th Aug
    Q4.1      1 Oct -15 Nov           1st Oct
    Q4.2      16 Nov – 31 Dec      16th Nov
    The dropdown values in time window needs to be updated as per date entered by the user in the Audit Plan start date and
    should display the next four Quarter (each divided in 2 half  i.e. Eight values ) along with the year  from the selected Audit plan start date.
    for eg. If the Plan start date is given as August 10 2013 then the Time window will display the following options:                      
    Q3.2 (2013)                
    Q 4.1 (2013)               
    Q 4.2 (2013)               
    Q 1.1 (2014)               
    Q1.2 (2014)                
    Q2.1 (2014)                
    Q 2.2 (2014)               
    Q 3.1 (2014)               
    You can refer to the Table above and look that 10 Aug 2013 falls under the Q3.1 so Time window will display the next next 8 half Quarters ( Total 4 Quarter) till Q 3.1 for the year 2014.

    Hello,
    WITH half_quarters AS(
        SELECT  ADD_MONTHS(TRUNC(DATE '2013-08-15','Q'), 3*(LEVEL - 1)) hq_start
               ,1 part
        FROM    dual
        CONNECT BY ROWNUM <= 5
        UNION ALL
        SELECT  ADD_MONTHS(TRUNC(DATE '2013-08-15','Q'), 3*(LEVEL - 1) + 1) + 15 hq_start
               ,2 part
        FROM    dual
        CONNECT BY ROWNUM <= 5
    ,ordered_half_quarters AS(
        SELECT  hq_start
               ,part
               ,ROW_NUMBER() OVER (ORDER BY hq_start) r
        FROM    half_quarters
        WHERE   hq_start > DATE '2013-08-15'
    SELECT  'Q '||TO_CHAR(hq_start,'Q')||'.'||part||' ('||TO_CHAR(hq_start,'YYYY')||')' q
    FROM    ordered_half_quarters
    WHERE   r <= 8
    ORDER BY r;
    Q       
    Q 3.2 (2013) 
    Q 4.1 (2013) 
    Q 4.2 (2013) 
    Q 1.1 (2014) 
    Q 1.2 (2014) 
    Q 2.1 (2014) 
    Q 2.2 (2014) 
    Q 3.1 (2014) 
    half_quarters generates the start dates of every half of a quarter, starting with the begin of the first quarter that contains the sample date.
    The next step is to order the dates and to select only those after the sample date.
    The last part formats the output and orders the data.
    Regards
    Marcus

  • Show Rows Where Two Columns have Same Data

    Hello,
    I have a spreadsheet that I need to sort by showing me all the rows where the data is equal between two columns.
    I.E. I have a column called Last Name and I have another column, U, with some of those Last Names, I want to sort the spreadsheet to show me only the rows that match up with the same Last Name in coumn a and U.
    Thanks for any help.
    L

    To sort the table:
    Add two columns to the table. For this discussion, I'll refer to them as columns AA and AB.
    In AA2, enter: =ROW()
    Fill to the bottom of the table. With all f these cells selected, Copy, then Edit > Paste Values.
    This gives you a column you can sort by to restore the original order of the table.
    In AB2, enter: =IF(A=U,U," ") using option-space between the double quotes.
    Visually, this will repeat the duplicated names once more in column AB.
    An ascending sort on column AB will bring all rows with duplicate data in columns A and U to the top of the table.
    For greater visibility You might also add a conditional format rule to all of column AB, as I've done here for column D:
    The box to the right of "Text doesn't contain" contains a single 'option-space' character. The ascending sort (on column D) has not yet been done.
    Regards,
    Barry

  • No rows returned with where number_value

    Hi all,
    Im using Oracle 10.2.0.1 on Windows 2000.
    I got something strange here.
    I have a table like:
    TABLE_NAME                     COLUMN_NAME                    DATA_TYPE        DATA_LENGTH DATA_PRECISION DATA_SCALE
    TEST                           COL1                           NUMBER                    22           1     0when I try to perform a query like:
    select * from test where col = 0this returns 0 rows.
    when I do:
    select * from test;
          COL1
             1
             1
             1
             1
             0
             0
             2but when a use to_number, it returns rows for zero value:
    select * from test where to_number(col) = 0;
          COL1
             0
             0somebody knows about this strange problem?
    thank you very much!!!!
    []´s

    Hi,
    >>I´m trying to understand this.
    Me too ;-)
    SQL> create table test (col1 number);
    Table created.
    SQL> alter table test add constraint ck_test check (col1 in ('0','1'));
    Table altered.
    SQL> insert into test values (0);
    1 row created.
    SQL> select * from test where col1=0;
    no rows selected
    SQL> explain plan for select * from test where col1=0;
    Explained.
    SQL> set linesize 130
    SQL> set pagesize 0
    SQL> select * from table(dbms_xplan.display);
    Plan hash value: 766971379
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |    13 |     0   (0)|          |
    |*  1 |  FILTER            |      |       |       |            |          |
    |*  2 |   TABLE ACCESS FULL| TEST |     1 |    13 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - filter(NULL IS NOT NULL)
       2 - filter("COL1"=0)
    Note
       - dynamic sampling used for this statement
    19 rows selected.
    SQL> select * from test where to_char(col1)=0;
          COL1
             0
    SQL> explain plan for select * from test where to_char(col1)=0;
    Explained.
    SQL> set linesize 130
    SQL> set pagesize 0
    SQL> select * from table(dbms_xplan.display);
    Plan hash value: 1357081020
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     1 |    13 |     3   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| TEST |     1 |    13 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - filter(TO_NUMBER(TO_CHAR("COL1"))=0)
    Note
       - dynamic sampling used for this statement
    17 rows selected.Cheers
    Legatti

Maybe you are looking for