Query For Xquery Implementation of Date Function

Hi All,
Objective: In array Item, I have to check for device entry Dates.
First device entry date would be the date corresponding to device seq no =0
Latest entry date would be the date corresponding to max device seq no.
Diff date should be differnce between first entry date and latest entry dates in days.
Output should be like
<FirstEntrydate></FirstEntrydate>
<LatestEntryDate></LatestEntryDate>
<Diffdate></Diffdate>
<Maxdevice Seq no></MaxdeviceSeqno>
the XML to transform is :
<?xml version="1.0"?>
<ns0:contractDeviceHistory xmlns:ns0="http://www.lhsgroup.com/ws_v3">
<ns0:item>
*<ns0:deviceEntryDate>*
*<ns0:date>2015-01-09T09:30:22</ns0:date>*
*</ns0:deviceEntryDate>*
<ns0:deviceId>3</ns0:deviceId>
<ns0:deviceModDate>
<ns0:date>2013-01-21T09:30:22</ns0:date>
</ns0:deviceModDate>
<ns0:devicePort>devicePort_1</ns0:devicePort>
*<ns0:deviceSeqno>2</ns0:deviceSeqno>*
<ns0:deviceSmNum>deviceSmNum_1</ns0:deviceSmNum>
<ns0:deviceStatus>deviceStatus_1</ns0:deviceStatus>
<ns0:deviceUserLastMod>deviceUserLastMod_1</ns0:deviceUserLastMod>
<ns0:deviceValidFrom>
<ns0:date>2013-01-06T09:30:22</ns0:date>
</ns0:deviceValidFrom>
<ns0:hlcode>32</ns0:hlcode>
<ns0:hlcodePub>hlcodePub_1</ns0:hlcodePub>
<ns0:reason>64</ns0:reason>
</ns0:item>
<ns0:item>
*<ns0:deviceEntryDate>*
*<ns0:date>2014-01-09T09:30:22</ns0:date>*
*</ns0:deviceEntryDate>*
<ns0:deviceId>3</ns0:deviceId>
<ns0:deviceModDate>
<ns0:date>2013-01-21T09:30:22</ns0:date>
</ns0:deviceModDate>
<ns0:devicePort>devicePort_1</ns0:devicePort>
*<ns0:deviceSeqno>1</ns0:deviceSeqno>*
<ns0:deviceSmNum>deviceSmNum_1</ns0:deviceSmNum>
<ns0:deviceStatus>deviceStatus_1</ns0:deviceStatus>
<ns0:deviceUserLastMod>deviceUserLastMod_1</ns0:deviceUserLastMod>
<ns0:deviceValidFrom>
<ns0:date>2013-01-06T09:30:22</ns0:date>
</ns0:deviceValidFrom>
<ns0:hlcode>32</ns0:hlcode>
<ns0:hlcodePub>hlcodePub_1</ns0:hlcodePub>
<ns0:reason>64</ns0:reason>
</ns0:item>
<ns0:item>
*<ns0:deviceEntryDate>*
*<ns0:date>2012-01-09T09:30:22</ns0:date>*
*</ns0:deviceEntryDate>*
<ns0:deviceId>3</ns0:deviceId>
<ns0:deviceModDate>
<ns0:date>2012-01-21T09:30:22</ns0:date>
</ns0:deviceModDate>
<ns0:devicePort>devicePort_1</ns0:devicePort>
*<ns0:deviceSeqno>0.0</ns0:deviceSeqno>*
<ns0:deviceSmNum>deviceSmNum_1</ns0:deviceSmNum>
<ns0:deviceStatus>deviceStatus_1</ns0:deviceStatus>
<ns0:deviceUserLastMod>deviceUserLastMod_1</ns0:deviceUserLastMod>
<ns0:deviceValidFrom>
<ns0:date>2013-01-06T09:30:22</ns0:date>
</ns0:deviceValidFrom>
<ns0:hlcode>32</ns0:hlcode>
<ns0:hlcodePub>hlcodePub_1</ns0:hlcodePub>
<ns0:reason>64</ns0:reason>
</ns0:item>
</ns0:contractDeviceHistory>
The Incomplete Xquery i wrote is this, which is not working. Plz suggest
declare function xf:SIMReplacementInfoResBSCSToSiebel($contractDeviceHistory1 as element())
as element(ns0:SIMReplacementResponse) {
<ns0:SIMReplacementResponse>
<ns0:SIMReplacement>
for $item in $contractDeviceHistory1/ns1:item
group $item as $group by
               $item/ns1:deviceSeqno as $key1,
                    $item/ns1:deviceEntryDate/ns1:date as $key2
               order by $key1 descending
return
<ns0:SIMReplacement
MaxDeviceSeqNo= "{ fn:max($key1) }"
FirstEntry_date = "{if(($key1) = '0.0')then($key2) else (0)}"
LatestEntry_date="{if(($key1)= fn:max($key1))then($key2) else ($key2)}"
/> }
<ns0:Status>Success</ns0:Status>
</ns0:SIMReplacement>
</ns0:SIMReplacementResponse>
declare variable $contractDeviceHistory1 as element() external;
xf:SIMReplacementInfoResBSCSToSiebel($contractDeviceHistory1)
Regards
Manu
India.

Post Author: jsiegmund
CA Forum: Data Connectivity and SQL
Not really, that function is a start, but to calculate the true ammount of work days there are a lot more variables to take into account. For instance, easter depends on the easter sunday which isn't a fixed date. In one year it may be in may, in the next it's in april. So defining a list of holidays (as done in the function in your example) isn't going to cut it. Therefore I mentioned implementing the function in Crystal Reports is a hard job which I wouldn't gladly take on. In the meantime, I've come upon an other solution using SQL Server 2005. It's possible to use assembly's in SQL Server, so I compiled the function as an assembly and loaded that into SQL Server. I needed information from the database for my reports anyway, so now I'm able to do the calculations in the views in the database, instead of leaving that to Crystal. Somewhat of a different solution, but it works for now. It would be great if future versions of Crystal would support the loading of assembly files though

Similar Messages

  • Query for months & quarter in date functions

    Hi All
    Could some on assist me how to get Last Year 1st,2nd,,, months and Current Year 1st,2nd,3rd,,, months and same way Quarterly please.
    I have date column Trade_date (dd/Mon/yyyy), Trade_price in Trade table
    DB:Oracle 11g
    Any assist would be appreciated

    All you have done is repeat your unclear question with more words.
    Here is how to get all the months for prior year and this year
    SQL> alter session set nls_date_format = 'Mon-YYYY';
    Session altered.
    SQL> select
      2      add_months(this_year, - 12) last_year,
      3      this_year
      4  from
      5      (
      6      select
      7          add_months(trunc(sysdate,'y'), level - 1)    this_year
      8      from
      9          dual
    10      connect by
    11          level <= 12
    12      );
    LAST_YEA THIS_YEA
    Jan-2010 Jan-2011
    Feb-2010 Feb-2011
    Mar-2010 Mar-2011
    Apr-2010 Apr-2011
    May-2010 May-2011
    Jun-2010 Jun-2011
    Jul-2010 Jul-2011
    Aug-2010 Aug-2011
    Sep-2010 Sep-2011
    Oct-2010 Oct-2011
    Nov-2010 Nov-2011
    Dec-2010 Dec-2011
    12 rows selected.And quarters
    SQL> select
      2      add_months(this_year, - 12) last_year,
      3      this_year
      4  from
      5      (
      6      select
      7          add_months(trunc(sysdate,'y'), (level - 1) * 3)    this_year
      8      from
      9          dual
    10      connect by
    11          level <= 4
    12      );
    LAST_YEA THIS_YEA
    Jan-2010 Jan-2011
    Apr-2010 Apr-2011
    Jul-2010 Jul-2011
    Oct-2010 Oct-2011
    SQL> alter session set nls_date_format = 'dd/mm/yyyy';
    Session altered.
    SQL> select
      2      add_months(this_year, - 12) last_year,
      3      this_year
      4  from
      5      (
      6      select
      7          add_months(trunc(sysdate,'y'), (level - 1) * 3)    this_year
      8      from
      9          dual
    10      connect by
    11          level <= 4
    12      );
    LAST_YEAR  THIS_YEAR
    01/01/2010 01/01/2011
    01/04/2010 01/04/2011
    01/07/2010 01/07/2011
    01/10/2010 01/10/2011As you can see from the second example, the display format of dates is controlled by the session,
    >
    he date column is trade_date (dd/mm/yyyy)
    >
    So this is still incorrect - if it is a date the format is not dd/mm/yyyy and, it is still not clear how this relates to your other questions.

  • MDX query for to get the data from two cubes

    Hi
    Can you tell me how to create MDX query to get the values from two cubes.  (One hierarchy from first cube and one hierarchy from second cube)
    Can you give me one example.
    Regards,
    Madhu.
    Sudhan

    Hi Sudhan,
    According to your description, you want to retrieve data from two different cubes, right? The short answer is yes. To query multiple cubes from a single MDX statement use the LOOKUPCUBE function (you can't specify multiple cubes in your FROM statement).
    The LOOKUPCUBE function will only work on cubes that utilize the same source database as the cube on which the MDX statement is running. For the detail information about it, please refer to the link below to see the blog.
    Retrieving Data From Multiple Cubes in an MDX Query Using the Lookupcube Function
    Regards,
    Charlie Liao
    TechNet Community Support

  • Best Practice for Package Implementation of Data Manipulation

    Hi,
    Would like to ask which is better implementation for data manipulation (insert, update, delete) stored procedure for a single table.
    To create a single procedure with input parameter for the action such as 1 for insert, 2 for update and so on
    or
    to create separate procedures for each like procedure pInsData for insert, pUpdData for update...

    Hi,
    Whenever you create a procedure it resides as a seperate object in database.
    In my opinion its better to create a single procedure which takes care of all DML concern to a table, rather than creating different procedures for each DML.
    If your number of DML are more and interrelated then its better to create a package and put all related DML procedures in the package concern to one transaction or table. This is because whenever you will call a package entire package will be placed in the memory for a particular session. So if you create different procedures for DML then you need to call the procedures each time you want it to be executed.
    Twinkle

  • Query for an in between date

    I need to make a query that checks to see if the start_date is less than sysdate and the end_date is greater than sysdate
    SELECT * FROM table WHERE OFFICE_START_DATE < SYSDATE AND OFFICE_END_DATE > SYSDATE
    What is the easiest way of doing this?
    Thanks

    user9179751 wrote:
    It wasn't working for me initially but I had to format the date to validate.
    SELECT * FROM TABLE WHERE OFFICE_START_DATE < TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')
    AND OFFICE_END_DATE > TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS');As skvaish said, it looks as if your columns are character (varchar2, most likely) and not dates. And if so, your solution is still buggy. You should be doing
    select *
    from mytable
    where to_date(office_start_date) < sysdate
      and  to_date(office_end_date) > sysdate;If you insist on thinking that a chracter string that looks like a date is a date, what do you make of this:
    First, create a table with a char column used as a date:
    SQL> drop table mydemo;
    Table dropped.
    SQL> create table mydemo (
      2  alfa_date varchar2(11),
      3  rite_date date
      4  );
    Table created.Now insert some data
    SQL> --
    SQL> insert into mydemo values ('01-JAN-2010', to_date('01-JAN-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('01-FEB-2010', to_date('01-FEB-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('01-APR-2010', to_date('01-APR-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('02-JAN-2010', to_date('02-JAN-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('02-FEB-2010', to_date('02-FEB-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('02-APR-2010', to_date('02-APR-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('03-JAN-2010', to_date('03-JAN-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('03-FEB-2010', to_date('03-FEB-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('03-APR-2010', to_date('03-APR-2010','DD-MON-YYYY'));
    1 row created.
    SQL> commit;
    Commit complete.Now, select, and order on the alfa-date;
    SQL> select * from mydemo order by alfa_date;
    ALFA_DATE   RITE_DATE
    01-APR-2010 01-APR-10
    01-FEB-2010 01-FEB-10
    01-JAN-2010 01-JAN-10
    02-APR-2010 02-APR-10
    02-FEB-2010 02-FEB-10
    02-JAN-2010 02-JAN-10
    03-APR-2010 03-APR-10
    03-FEB-2010 03-FEB-10
    03-JAN-2010 03-JAN-10
    9 rows selected.Are they in date sequence?
    No they are not.
    Why not?
    Now select, and order on the properly defined date column.
    SQL> select * from mydemo order by rite_date;
    ALFA_DATE   RITE_DATE
    01-JAN-2010 01-JAN-10
    02-JAN-2010 02-JAN-10
    03-JAN-2010 03-JAN-10
    01-FEB-2010 01-FEB-10
    02-FEB-2010 02-FEB-10
    03-FEB-2010 03-FEB-10
    01-APR-2010 01-APR-10
    02-APR-2010 02-APR-10
    03-APR-2010 03-APR-10
    9 rows selected.
    SQL> spo off

  • Query For Large Amount of Data

    Hello All,
    I apologize in advance if I am not posting this in the right section. I am fairly new to APEX and database designing. My goal is to create an inquiry screen for a database of people.
    I am running APEX 4.2 on 11g. The information is store in 3 tables; Names, Demographics, Address. Each table had a PIN ID column that ties them all together. Each table has almost a million rows in them.
    Currently I have it set up that the person types in the name they want to search and it gets passed into a hidden page item on the next page where there is a report with a select statement based on the page item. Everything works right now however it is slow. I am having a 5-10 second delay before the results come up.
    My question is, is there a better way to set up these tables. What is the best way to make this faster?
    I'm sorry if this is a vague question but any help, or point in the right direction will be greatly appreciated
    Thank You !

    976533 wrote:
    Hello All,Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your forum profile with a real handle instead of "976533".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    I apologize in advance if I am not posting this in the right section. I am fairly new to APEX and database designing. My goal is to create an inquiry screen for a database of people.It might be more appropriate to the {forum:id=75} forum, so you should look at the following entries on their FAQ as well:
    <li>{message:id=9360002}
    <li>{message:id=9360003}
    I am running APEX 4.2 on 11g. The information is store in 3 tables; Names, Demographics, Address. Each table had a PIN ID column that ties them all together. Each table has almost a million rows in them.
    Currently I have it set up that the person types in the name they want to search and it gets passed into a hidden page item on the next page where there is a report with a select statement based on the page item. Everything works right now however it is slow. I am having a 5-10 second delay before the results come up.
    My question is, is there a better way to set up these tables. What is the best way to make this faster? Are there suitable indexes on the tables?
    Does the report query use them?
    As described above, either: reproduce the problem on apex.oracle.com; or post DDL to allow us to recreate the tables and indexes, and the SQL from your report.

  • Query for Business Partner  Master data

    Respected Sir/Madam,
                           I want a Query in Bp Master Data----> "Name" Should Allow Only Capital Letters.Can anyone please helpme out from this.

    Hi,
    Apply FMS to BP Name field.
    Set below query in FMS and tick auto refresh with "When Exiting Altered Column" and select field Quantity and select "Refresh Regularly" .
    Select UCASE($[OCRD.CardName)
    Regards,
    Clint

  • Query for below scenario using analytical  functions

    Hi,
    Below is the data format which I have.
    COL-1     COL-2
    1-Jan-13     5
    2-Jan-13     
    3-Jan-13     
    4-Jan-13     
    5-Jan-13     10
    6-Jan-13     
    7-Jan-13     
    8-Jan-13     
    9-Jan-13     15
    10-Jan-13     
    Expected
    COL-1     COL-2
    1-Jan-13     5
    2-Jan-13     5
    3-Jan-13     5
    4-Jan-13     5
    5-Jan-13     10
    6-Jan-13     10
    7-Jan-13     10
    8-Jan-13     10
    9-Jan-13     15
    10-Jan-13     15;
    Thanks in advance
    Edited by: unique on May 14, 2013 2:23 PM

    unique wrote:
    Hi,
    Below is the data format which I have.
    COL-1     COL-2
    1-Jan-13     5
    2-Jan-13     
    3-Jan-13     
    4-Jan-13     
    5-Jan-13     10
    6-Jan-13     
    7-Jan-13     
    8-Jan-13     
    9-Jan-13     15
    10-Jan-13     
    Expected
    COL-1     COL-2
    1-Jan-13     5
    2-Jan-13     5
    3-Jan-13     5
    4-Jan-13     5
    5-Jan-13     10
    6-Jan-13     10
    7-Jan-13     10
    8-Jan-13     10
    9-Jan-13     15
    10-Jan-13     15;
    Thanks in advance
    Edited by: unique on May 14, 2013 2:23 PMAny rationale behind your output?
    How about you try to explain WHY the output is supposed to be as you ask for.
    I can think of more than 1 way to do this, each of which would be wrong if I make the wrong assumption about what you are actually trying to do.
    Cheers,

  • Query for selecting distinct by date

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    I have a simple table that has an ID, Title, and Date.
    I need to select the most recent ID (without duplicates). I was looking at using a UNION but couldn't quite get it to work.
    P3XGL2FV96     Test 1     11-AUG-10 03.38.06.000000000 PM
    1VGJ74PSNW     Test 2     11-AUG-10 04.02.22.000000000 PM
    1VGJ74PSNW     Test 2     12-AUG-10 09.49.09.000000000 AM

    Hi,
    You could achieve it like this :
    CREATE TABLE MY_TABLE
    +(+
    ID       VARCHAR2(10),
    TITLE    VARCHAR2(10),
    MY_DATE TIMESTAMP
    +);+
    insert into my_table values ('P3XGL2FV96', 'Test 1', '11-AUG-10 03.38.06.000000000 PM');
    insert into my_table values ('1VGJ74PSNW', 'Test 2', '12-AUG-10 09.49.09.000000000 AM');
    insert into my_table values ('1VGJ74PSNW', 'Test 2', '11-AUG-10 04.02.22.000000000 PM');
    commit;
    SELECT id, title, my_date
    FROM (SELECT id,
    title,
    my_date,
    RANK () OVER (PARTITION BY id ORDER BY my_date DESC) rk
    FROM my_table)
    WHERE rk = 1;
    ID        |TITLE     |MY_DATE
    ----------|----------|---------------------------------------------------------------------------
    +1VGJ74PSNW|Test 2 |12-AUG-10 09.49.09.000000 AM+
    P3XGL2FV96|Test 1    |11-AUG-10 03.38.06.000000 PM
    Remark : if one id have twice the same date they will be both ranked first
    Kind regards,
    Ludovic
    Edited by: ludovic.sz on Aug 12, 2010 8:38 AM

  • Query for getting combination of data

    hi all,
    i am using db10g.
    i have a table of fields a_company,a_code,a_name,a_port,a_t_port,a_rate,a_volume
    i have a records like
    MM,AA,A-NAME,EFG,EFGH,100,20
    MM,AA,A-NAME,EFG,EFGH,200,10
    MM,BB,B-NAME,HIJ,HIJK,100,20
    MM,BB,B-NAME,HIJ,HIJK,200,30
    MM,CC,C-NAME,DEF,DEFG,500,20i have to select all columns but the fields if below below combination repeates(having more than 1 combination)
    a_company,a_code,a_port,a_t_port
    how can form a query?
    in other words i am expecting the result like below among above said input.
    MM,AA,A-NAME,EFG,EFGH,100,20
    MM,AA,A-NAME,EFG,EFGH,200,10
    MM,BB,B-NAME,HIJ,HIJK,100,20
    MM,BB,B-NAME,HIJ,HIJK,200,30Thanks..

    With only one table scan:
    SQL> create table a_table (a_company,a_code,a_name,a_port,a_t_port,a_rate,a_volume)
      2  as
      3  select 'MM','AA','A-NAME','EFG','EFGH',100,20 from dual union all
      4  select 'MM','AA','A-NAME','EFG','EFGH',200,10 from dual union all
      5  select 'MM','BB','B-NAME','HIJ','HIJK',100,20 from dual union all
      6  select 'MM','BB','B-NAME','HIJ','HIJK',200,30 from dual union all
      7  select 'MM','CC','C-NAME','DEF','DEFG',500,20 from dual
      8  /
    Table created.
    SQL> exec dbms_stats.gather_table_stats(user,'a_table')
    PL/SQL procedure successfully completed.
    SQL> set autotrace on explain
    SQL> select a_company
      2       , a_code
      3       , a_name
      4       , a_port
      5       , a_t_port
      6       , a_rate
      7       , a_volume
      8    from ( select a.a_company
      9                , a.a_code
    10                , a.a_name
    11                , a.a_port
    12                , a.a_t_port
    13                , a.a_rate
    14                , a.a_volume
    15                , count(*) over (partition by a_company,a_code,a_port,a_t_port) cnt
    16             from a_table a
    17         )
    18   where cnt > 1
    19  /
    A_ A_ A_NAME A_P A_T_     A_RATE   A_VOLUME
    MM AA A-NAME EFG EFGH        100         20
    MM AA A-NAME EFG EFGH        200         10
    MM BB B-NAME HIJ HIJK        100         20
    MM BB B-NAME HIJ HIJK        200         30
    4 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=4 Card=5 Bytes=330)
       1    0   VIEW (Cost=4 Card=5 Bytes=330)
       2    1     WINDOW (SORT) (Cost=4 Card=5 Bytes=140)
       3    2       TABLE ACCESS (FULL) OF 'A_TABLE' (Cost=2 Card=5 Bytes=140)Regards,
    Rob.

  • Query for spatial data with a GeometryCollection fails

    There are exact 538 CurvePolygons (only exterior rings at this
    sample). All of them are valid geometries and equal in dimension
    and so on. Now I connect them to a GeometryCollection and query
    for other relating spatial data in some tables. It seems that
    the use of around (not exact!) 200 CurvePolygon in one
    GeometryCollection works fine but the adding of more
    CurvePolygon result in an error with the Spatial Index (I could
    add the ORA- error numbers if I have some data in my test tables
    again next days).
    Is there anybody else having trouble with these mysterious
    problem? Maybe there is a border by the number of points in
    GeometryCollection?
    (More details, programming code could be delivered)
    (working with Java 1.3.1, oracle.sdoapi.*, Oracle 8.1.7.)

    Hi Lutz,
    Could you provide more info or samples of what is going wrong?
    Also, could you try making sure the geometry you are passing in
    as the query window is valid (i.e. instead of passing it in as a
    query window, pass it into sdo_geom.validate_geometry).
    Thanks,
    Dan

  • Query for select CLOB data field

    Hi All,
    I want to know how to write a SQL query for select CLOB tyoe data from a tablw. when I am trying to use the simple SQL it gives an messageLOB types requires OCI8 mode and currently uasing OCI7 ode.
    Also I am not aware of oci mode?
    If its working for OCI8 mode how I should changer it in to OCI8 mode? (I am using 10g rel 2)
    Thans and regards
    Buddhike

    Hi ,
    i don't want to use loop (sy-tabix) ..
    any particular reason for this ?
    as u cannot automatically generate serial number, u have to go for loop....endloop.
    Thanks
    Karthik

  • Run Query for Quarters

    I need query for Q1,Q2,Q3 data. Q is quarter.
    That is Q1=1 to 4
    Q2=4 to 8
    Q3=9 to 12
    I give above these parameters for this query.
    I select Q1 run this query. same run as Q2,Q3.
    (select d.valuedoc,
    (case when (d.el4='E9000') then 'Other Revenue' else '1' end ) as Line,
    h.yr,
    h.period
    from oas_dochead as h, oas_docline as d
    left outer join oas_grplist as g
    on d.el4=g.code and d.cmpcode=g.cmpcode and g.grpcode in ('21ONSITE', '21OFFSITE')
    where d.docnum=h.docnum
    and d.doccode=h.doccode
    and d.cmpcode=h.cmpcode
    and (h.yr between ?Year? - 3 and ?Year? and h.period between 1 and 4)
    )

    >
    I need query for Q1,Q2,Q3 data. Q is quarter.
    That is Q1=1 to 4
    Q2=4 to 8
    Q3=9 to 12Nope - they're not quarters - they're thirds.
    Quarters are 1-3, 4-6, 7-9, 10-12
    Kindly repost your query within
    .... tags - it's unreadable otherwise.
    Also, see my .sig for other information to post - DB version, OS
    &c.
    Paul...
    When asking database related questions, please give other posters
    some clues, like OS (with version), version of Oracle being used and DDL.
    Other trivia such as CPU, RAM + Disk configuration might also be useful.
    The exact text and/or number of error messages is useful (!= "it didn't work!"). Thanks.
    Furthermore, as a courtesy to those who spend time analysing and attempting to help,
    please do not top post and do try to trim your replies!

  • Invalid state in SQL query for a function that was created with no errors.

    SQL> CREATE OR REPLACE FUNCTION overlap(in_start1 IN TIMESTAMP, in_end1 IN TIMESTAMP, in_start2 IN TIMESTAMP, in_end2 IN TIMESTAMP) RETURN NUMBER
    2 IS
    3
    4 BEGIN
    5 IF (in_start1 BETWEEN in_start2 AND in_end2 OR in_end1 BETWEEN in_start2 AND in_end2 OR in_start2 BETWEEN in_start1 AND in_end1) THEN
    6 RETURN 0;
    7 ELSE
    8 RETURN 1;
    9 END IF;
    10 END;
    11 /
    Function created.
    SQL> show errors;
    No errors.
    SQL>
    SQL> SELECT * FROM tbl where overlaps(current_time,current_time+1,current_time-1,current_time+2) = 0;
    SELECT * FROM tbl where overlaps(current_time,current_time+1,current_time-1,current_time+2) = 0
    ERROR at line 1:
    ORA-06575: Package or function OVERLAPS is in an invalid state
    I do not understand why overlaps is returned as in invalid state in the query, when it was created with no errors earlier. Could anyone help me?

    Marius
    Looking at the logic you are trying to create it looks like you are looking for overlapping time periods.
    Consider two date/time ranges:
    Range 1 : T1 - T2
    Range 2 : T3 - T4
    Do they overlap?
    1) No: T1 < T4 (TRUE)  T2 > T3 (FALSE)
    T1 --- T2
               T3 --- T4
    2) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
    T1 ---------- T2
               T3 --- T4
    3) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
    T1 -------------------- T2
               T3 --- T4
    4) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
                   T1 ----- T2
               T3 --- T4
    5) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
               T1 --- T2
           T3 ------------ T4
    5) No: T1 < T4 (FALSE) T2 > T3 (TRUE)
                    T1 --- T2
           T3 --- T4Answer: Yes they overlap if:
    T1 < T4 AND T2 > T3
    So you can code the logic in your SQL as simply:
    SELECT *
    FROM tbl
    WHERE range1_start < range2_end
    AND    range_1_end > range2_startIf you go around implementing PL/SQL functions for simple logic that can be achieved in SQL alone then you cause context switching between the SQL and PL/SQL engines which degrades performance. Wherever possible stick to just SQL and only use PL/SQL if absolutely necessary.

  • Ms access 2007 between query for date

    Dear All,
    I am using the below query to fetch records from a table between two dates
    select * from tablename where Format([VisitDate],"Short Date") >=Format(#01/10/2014#,"Short Date") and Format([VisitDate],"Short Date") <=Format(#31/10/2014#,"Short Date")
    I want records between 1st Oct to 31st Oct only, but the above query shows Nov and December data also. Please let me know where I am going wrong.
    Regards,
    Noor 
    Thanks & Regards, Noor Hussain

    The Format function returns a string expression, so the comparison is on that basis not on the date value.  You do not need to worry about the format at all as the date/time data type in Access is implemented as a 64 bit floating point number. 
    You can see it in whatever date/time format you wish, but the underlying value is always the same.  When you include a date literal in an SQL statement or in VBA code it must be either in US short date format (mm/dd/yyyy), or in an internationally unambiguous
    format.  The ISO standard format for date notation of YYYY-MM-DD is a good choice.  So you query would be:
    SELECT *
    FROM tablename
    WHERE VisitDate  >=  #2014-10-01#
    AND VisitDate < #2014-11-01#;
    Note that the range is defined as on or after the start date and before the day following the end date.  This ensures that all relevant rows are returned.  As there is no such thing in Access as a 'date value', but only a 'date/time value' it is possible
    that a 'date' of 31 October 2014 could have a non-zero time of day element unless you have taken steps in the table definition to specifically exclude values with a non-zero time of day.  Such date/time values would not fall within a range ending <=
    #2014-10-31#, so would not be returned by the query.  Defining the end of the range with < #2014-11-01# ensures that such rows are returned.
    Ken Sheridan, Stafford, England

Maybe you are looking for

  • Why Does 3G Not Work on my IPhone

    Apologies everyone - I am a real numpty with my IPhone.  I have switched just about everything on i think I need to to enable 3G and my service provider says that in my present location the wireless service is excellent.  So why is that on my top too

  • Improving features?

    Help anyone, issue I have with iphone! * Camera is unable to zoom in or out * Unable to send pic text which I was able to do with my piece of crap razor without issues.. It send you to viewmymessage.com webpage, very inconvenient. * With the SMS prev

  • Pricing redetermination at the sales order

    Hi , We have mass order inquiry tool which will bring in the sales orders in the system and also updates certain fields defined in the tool. For example if we want to change the pricing date we just enter it & the tool will change it. Now we have a n

  • How do I uninstall OSX Tiger?

    I'll get right to the point. I need to remove OSX Tiger from my Mac. It has never run properly since installation over a year ago (just too slow) and I have been running on 10.2.8 instead (the two OS are on separate hard drives). Now the computer is

  • Don't see new UI in FF v21

    I have FF v21 for Windows but I don't see the updates to the UI. For instance, my tabs are still under my bookmark toolbar, I don't see the Firefox button in the top left and I don't see the bookmark button on the right. I'm using an add-on theme but