Sql query creating a view

Hi I need to create a simple view like this
No Count
10 15
to get the No i am using a function which would normally return 1 value like 10 above but could sometimes return 2 numbers in the following format 10:5
When I get a number like this i need to split it into 2 rows in the view with the same count.
No Count
10 15
5 15
at the moment i get this
No Count
10:5 15
5 15
I can use plsql or sql thanks in advance
kirk

Not sure i was clear enough so heres my view as it stands
CREATE OR REPLACE FORCE VIEW "Q_ABSENCE" ("OWNERID", "OWNERTYPE", "TYPE", "ITEMCOUNT") AS
select distinct 'No',
count(*) as itemcount
from sick_absence
where ab_proccessed =2
and AB_COORDPROCESSED = 'No'
group by ab_owner
Which would return the following data
NO Count
10 2
5 4
4:3 2
2 1
234:23 4
I need it to return
No Count
10 2
5 4
4 2
3 2
2 1
234 4
23 4
thanks for your time
Kirk

Similar Messages

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Passing an argument in the SQL Query of a View Object

    Hi,
    It is possible that this question has been asked before, however I have searched for a half an hour in the forums and couldn't find a solution.
    I am also new to using JDeveloper and ADF. Here's the situation:
    I am developing an application that doesn't have to do anything else then displaying data from a database. Pretty straightforward actually.
    Now I have made a vew pages with several collapsible panels (af:showDetailHeader) and have setup the datasources (or so I thought).
    All that remains is:
    - drag & drop a view object, from the application module that I created, onto the collabsible panels, so a child element gets created which displays data from the database.
    - hack the layout so it looks like I want it to.
    The problem that I have is the following:
    I am using a 'User'-class that contains values I need when quering the database.
    That User-object is part of a user-session.
    What I want, for example, is to use the 'getPersonId()' function of that User-object and pass the argument to a SQL-query of a certain view-object.
    The query would become something like:
    'SELECT * FROM people WHERE people.personId = :someNumber'.
    Now I've read some stuff about variable binding, which is complemented by something like (backing bean code):
    getDBTransaction().getRootApplicationModule().getACertainViewObject().setWhereClauseParameter(1, user.getPersonId());
    The examples I have found that might match my wishes are not using business components, but EJB's. I am having difficulty with understanding the 'how'-part of variable binding.
    Also, I do not know enough of ADF to be able to create a situation like:
    'User loads page, collapsible panel 1 is fully shown, the others are undisclosed.'
    (meaning, that for panel1 a query has been executed.)
    'User clicks on collapsible panel 2 which triggers a backingbean that somehow retrieves data from a view object'.
    I would appreciate any help that somebody can give.
    If it is not too much of a problem, please provide code snippets in case you have a solution. I am new to ADF :(.
    -edit
    I am using JDeveloper 10.1.3.3.0 in case that is of any importance.
    Message was edited by:
    Hugo Boog

    Hello Stijn,
    I didn't think about a referenced bean rule in the faces-config.
    I added it right away and I am now able to set parameters of a View-object, not using a page button and before the page loads. You made my day!
    In case anyone ever reads this post again, the summary of how to generate a table based on a View-object using dynamic parameters.:
    1a: Go to faces-config.xml -> Overview tab'
    1b: Go to the menuitem "Referenced Beans"
    1c: Click on 'new' and select the existing bean you want to access data from and input a name. In this example I use name="user"
    2: Create a View-object using the wizard.
    2a: Specify the query you want in the menuitem 'SQL Statement'.
    Add the 'parameters' you want to. You will have something like:
    "SELECT * FROM someTable WHERE table.columnname LIKE :someArgument".
    - hint: if you want the result to become something like:
    "SELECT * FROM someTable WHERE table.columnname LIKE '%someArgument%'" then you have to add the '%'-characters in your code itself (read: someClass.setParameter("%" + someArgument);).
    2b: In the menuitem 'Bind Variables' you have to add the variables you are referring to in the query. If you look at the query in 2a, then you have to add a variable with name "someArgument".
    2c: Add the View-object to a Application Module (create one if nessecairy).
    3a: Open a .jsp(x) file. Drag the View-object created in step 2 from the 'Data Controls'-pane to the page.
    3b: Click on the '+' of the View-object in the 'Data Controls'-pane and open 'Operations' and drag 'ExecuteWithParams' to your page as a button.
    3c: We do not want to use a button, the action has to be executed immediatly. So In the page source remove the lines that were created after dropping 'ExecuteWithParams'.
    3d: Right-click on the page and select "Go to Page Definition".
    3e: Go to the action id that is called 'ExecuteWithParams#', where # is a number.
    Change the id to something useful.
    3f: Change the NDValue so it corresponds with the value you want.
    Example:
    <action id="getAddressData" IterBinding="AddressesView1Iterator"
    InstanceName="MyHRServiceModuleDataControl.AddressView1"
    DataControl="MyHRServiceModuleDataControl" RequiresUpdateModel="true" Action="95">
    <NamedData NDName="someArgument" NDType="java.lang.String"
    NDValue="#{user.personId}"/>
    </action>
    Note: It is possible to use the value of a Backing Bean in NDValue.
    Note 2: user is the bean I referred to in the faces-config.xml!
    3g: Under the executables item, add an 'invokeAction' to pass the parameter to the View-object before your JSP-file loads:
    <executables>
    <invokeAction Binds="getAddressData"
    id="loadAddressDataOfPersonIdInSession"
    Refresh="prepareModel"/>
    Thank Stijn Haus for this :)

  • Using IN keyword in an sql query in a view criteria

    Hi,
    I am using jdev 11.1.1.1.0 and defined an lov query/viewobject as
    select a, b, c from myTable
    I now need to predefine filtering for lov search functionality and need something like the following
    select a, B, c from myTable where B in ('X','Y')
    I could not find a way to do it (i.e. specify the use of IN Keyword) in the Create View Criteria dialog box. I tried to define OR, but is that the best way to redefine IN as i have a long list (the above is just an example)
    (( ( (UPPER(B_FLAG) = UPPER('X') ) ) OR ( (UPPER(DISPLAY_FLAG) = UPPER('Y') ) ) ))

    If you know how many variables are in your "in" You can just write this in the sql query of your VO:
    http://www.oracle.com/technology/obe/obe11jdev/ps1/ria_application/images/t136.gif
    From this tutorial:
    http://www.oracle.com/technology/obe/obe11jdev/ps1/ria_application/developriaapplication_long.htm#ah1

  • MS SQL query slow using view column as criteria

    HI,
    I am experiencing a very frustrate problem. I have 2 tables, and create a view
    to union these 2 tables, when do a select on this view using the column of the
    view as criteria is took more 1 minutes, but the query runs fine in Qurey Analyzer.
    Anybody has the same experience? is this the problem with jdbc?

    I searched http://e-docs.bea.com/wls/docs70/index.html, also searched the documentation
    for wls6.1, wls5.1. As you pointed I searched support site, they are all the customer
    case, it's not formal documentation.
    Joe Weinstein <[email protected]> wrote:
    >
    >
    jen wrote:
    Thanks. but I search on the table is fine (the same column). is thereany db setting
    could be tuned? so the view is the problem? No, it's a client decision/issue. If you defined your tables to have
    nvarchar columns
    the jdbc driver's parameter values would be fine as-is.
    I searched "useVarChars" on whole
    site and can't find anything.Which site? This is a property of the weblogic.jdbc.mssqlserver4.Driver.
    I just went to www.bea.com/support and entered useVarChars in the Ask
    BEA
    question panel and got hits...
    Joe
    Joe Weinstein <[email protected]> wrote:
    Jen wrote:
    Sorry it's my bad. I am testing on wls81, but the problems is on wls70,so they
    are using different drivers.
    You are the magic man. It worked on wls81 now. I am sure it will curethe problem
    on wls70. Is there any documentation on this? Why it is not a problemon some
    databse server? ThanksSure. The issue has to do with the MS client-DBMS protocol having evolved
    from
    an 8-bit (7-bit really) character representation. Now it has a newer
    16-bit
    way, to transfer NVARCHAR data. Java characters are all 16-bit, so
    by default
    a JDBC driver will send Java parameters over as NVARCHAR data. This
    is
    crucial
    for Japanese data etc. However, once simple ASCII data is transformed
    to an
    NVARCHAR format, the DBMS can't directly compare it to varchar data,
    or use it
    in index searches. The DBMS has to convert the VARCHAR data to NVARCHAR,
    but it
    can't guarantee that the converted data will retain the same ordering
    as the index,
    so the DBMS has to do a table scan!
    The properties I suggested are each driver's way of allowing you
    to say "I'm
    a simple American ;) I am using simple varchar data so please sendmy
    java
    strings that way.". This allows the DBMS to use your varchar indexes
    in queries.
    Joe Weinstein at BEA
    Joe Weinstein <[email protected]> wrote:
    Jen wrote:
    It doesn't cure the problem. Here is my pool
    <JDBCConnectionPool DriverName="weblogic.jdbc.sqlserver.SQLServerDriver"Name="test_pool"
    Password="{3DES}fKSovViFe5kHzl/vTs0LVQ==" Properties="user=user;PortNumber=1543;useVarChars=true;ServerName=194.20.2.10;DatabaseName=devDB"
    Targets="admin" TestTableName="SQL SELECT COUNT(*) FROM sysobjects"URL="jdbc:bea:sqlserver://194.20.2.10:1543"/>
    Strange is some database is fine.Oh, sorry. I thought it was the older weblogic driver. Change the
    useVarChars=true to sendStringParametersAsUnicode=false
    Let me know... Also, I suggest changing the TestTableName to "SQL
    select
    1".
    For MS, that will be much more efficient than involving a full count
    of sysobjects!
    Joe
    Joe Weinstein <[email protected]> wrote:
    Jen wrote:
    You are right. Tadaa! Am I Kreskin, or what? ;) Here's what I recommend:
    In your pool definition, for this driver add a driver property:
    useVarChars=true
    and let me know if it's all better.
    Joe
    I am using weblogic jdbc driver weblogic.jdbc.mssqlserver4.Driver.
    here is the code:
    getData(Connection connection, String stmt, ArrayList arguments)
         PreparedStatement pStatement=null;>>>>>>>>     ResultSet resultSet=null;>>>>>>>>     try {>>>>>>>>         pStatement = connection.prepareStatement(stmt);>>>>>>>>         for (int i = 1; i <= arguments.size(); i++) {>>>>>>>>          pStatement.setString(i, (String) arguments.get(i-1));>>>>>>>>                    resultSet = pStatement.executeQuery(); //this statement takesmore than 1
    min.
    Joe Weinstein <[email protected]> wrote:
    Jen wrote:
    HI,
    I am experiencing a very frustrate problem. I have 2 tables,
    and
    create
    a view
    to union these 2 tables, when do a select on this view using
    the
    column
    of the
    view as criteria is took more 1 minutes, but the query runs
    fine
    in
    Qurey Analyzer.
    Anybody has the same experience? is this the problem with jdbc?
    I have suspicions... Show me the jdbc code. I'm guessing it's
    a
    PreparedStatement,
    and you send the search criterion column value as a parameter
    you
    set
    with a
    setString().... Let me know... (also let me know which jdbc driveryou're
    using).
    Joe

  • Please help with the query creating Materialized View

    Hi,
    We are using the below query to create a Materialized View but it has been running since 3 hours. It is an Oracle 9i database running in HP-UX.The quey is as follows,
    (SELECT
    /*+ use_nl(A) parallel (A,4)*/
    A.ICD_CODE AS ICD_CODE,
    A.ICD_DESC AS ICD_DESC,
    A.PROC_GROUP as PROC_GROUP,
    B.COMPL_ICD_CODE AS COMPL_ICD_CODE,
    B.COMPL_GRP_TXT AS COMPL_GRP_TXT,
    C.PROC_TYPE AS PROC_TYPE ,
    C.I_O_IND AS I_O_IND,
    C.DISC_MON AS QUARTER ,
    B.PAT_KEY AS PAT_KEY ,
    D.COMPL_TYPE_TXT AS COMPL_TYPE_TXT ,
    C.PROV_ID AS PROV_ID ,
    A.SPECIALTY AS SPECIALTY
    FROM
    EES_ICD_9_CODE A ,
    EES_CLINICAL_COMPL_DATA B,
    EES_CLINICAL_DATA C,
    EES_CLINCL_COMPL_ICD D                                                                            
    WHERE A.ICD_CODE= B.ICD_CODE
                    AND B.ICD_CODE= C.ICD_CODE
                    AND B.COMPL_ICD_CODE=D.ICD_9_CD
                    AND B.PAT_KEY=C.PAT_KEY
                    AND B.COMPL_ICD_CODEB.ICD_CODE
                    AND C.PROC_TYPE  'L'
                    AND B.COMPL_GRP_TXT'Reoperations'
                    AND D.COMPL_TYPE_TXT'Intra-operative Misadventure'
                    AND C.DISC_MON>='2003101'
                    AND A.SPECIALTY='Colo-Rectal')
    union
    (SELECT
    /*+ use_nl(A) parallel (A,4)*/
    A.ICD_CODE AS ICD_CODE,
    A.ICD_DESC AS ICD_DESC,
    A.PROC_GROUP as PROC_GROUP,
    B.COMPL_ICD_CODE AS COMPL_ICD_CODE,
    B.COMPL_GRP_TXT AS COMPL_GRP_TXT,
    C.PROC_TYPE AS PROC_TYPE ,
    C.I_O_IND AS I_O_IND,
    C.DISC_MON AS QUARTER ,
    B.PAT_KEY AS PAT_KEY ,
    D.COMPL_TYPE_TXT AS COMPL_TYPE_TXT ,
    C.PROV_ID AS PROV_ID ,
    A.SPECIALTY AS SPECIALTY
    FROM
    EES_ICD_9_CODE A ,
    EES_CLINICAL_COMPL_DATA B,
    EES_CLINICAL_DATA C,
    EES_CLINCL_COMPL_ICD D                                                                            
    WHERE A.ICD_CODE= B.ICD_CODE
                    AND B.ICD_CODE= C.ICD_CODE
                    AND B.COMPL_ICD_CODE=D.ICD_9_CD
                   AND B.PAT_KEY=C.PAT_KEY
                    AND B.COMPL_ICD_CODEB.ICD_CODE
                    AND C.PROC_TYPE  'L'
                    --AND B.COMPL_GRP_TXT'Reoperations'
                    AND D.COMPL_TYPE_TXT='Intra-operative Misadventure'
                    AND B.PROC_DAY=C.PROC_DAY
                    AND C.DISC_MON>='2003101'
                    AND A.SPECIALTY='Colo-Rectal')
    union
    (SELECT
    /*+ use_nl(A) parallel (A,4)*/
    A.ICD_CODE AS ICD_CODE,
    A.ICD_DESC AS ICD_DESC,
    A.PROC_GROUP as PROC_GROUP,
    B.COMPL_ICD_CODE AS COMPL_ICD_CODE,
    B.COMPL_GRP_TXT AS COMPL_GRP_TXT,
    C.PROC_TYPE AS PROC_TYPE ,
    C.I_O_IND AS I_O_IND,
    C.DISC_MON AS QUARTER ,
    B.PAT_KEY AS PAT_KEY ,
    D.COMPL_TYPE_TXT AS COMPL_TYPE_TXT ,
    C.PROV_ID AS PROV_ID ,
    A.SPECIALTY AS SPECIALTY
    FROM
    EES_ICD_9_CODE A ,
    EES_CLINICAL_COMPL_DATA B,
    EES_CLINICAL_DATA C,
    EES_CLINCL_COMPL_ICD D                                                                            
    WHERE A.ICD_CODE= B.ICD_CODE
                    AND B.ICD_CODE= C.ICD_CODE
                    AND B.COMPL_ICD_CODE=D.ICD_9_CD
                    AND B.PAT_KEY=C.PAT_KEY
                    AND B.COMPL_ICD_CODEB.ICD_CODE
                    AND C.PROC_TYPE  'L'
                    AND B.COMPL_GRP_TXT='Reoperations'
                    --AND D.COMPL_TYPE_TXT='Intra-operative Misadventure'
                    AND B.PROC_DAY>C.PROC_DAY
                    AND C.DISC_MON>='2003101'
                    AND A.SPECIALTY='Colo-Rectal')
    The explain plan is as follows,
    PLAN_TABLE_OUTPUT
    | Id  | Operation                          |  Name                    | Rows  | Bytes |TempSpc| Cost  |  TQ    |IN-OUT| PQ Distrib |
    |   0 | SELECT STATEMENT                   |                          | 46935 |  6716K|       | 10648 |        |      |            |
    |   1 |  SORT UNIQUE                       |                          | 46935 |  6716K|    14M| 10648 | 45,14  | P->S | QC (RAND)  |
    |   2 |   UNION-ALL                        |                          |       |       |       |       | 45,13  | P->P | HASH       |
    |*  3 |    HASH JOIN                       |                          | 42801 |  6102K|       |  4640 | 45,13  | PCWP |            |
    |*  4 |     TABLE ACCESS FULL              | EES_CLINCL_COMPL_ICD     |   875 | 18375 |       |     2 | 45,02
    |*  5 |     HASH JOIN                      |                          | 41552 |  5072K|    14M|  4638 | 45,13  | PCWP |            |
    |*  6 |      TABLE ACCESS FULL             | EES_CLINICAL_DATA        |  1430K|    40M|       |  2855 | 45,03
    |*  7 |      HASH JOIN                     |                          |   628K|    56M|       |   494 | 45,10  | P->P | HASH       |
    |*  8 |       TABLE ACCESS FULL            | EES_ICD_9_CODE           |    37 |  2183 |       |     1 | 45,08 
    |*  9 |       TABLE ACCESS BY INDEX ROWID  | EES_CLINICAL_COMPL_DATA  |  2090K|    71M|       |   49
    |  10 |        BITMAP CONVERSION TO ROWIDS |                          |       |       |       |       |        |    
    |* 11 |         BITMAP INDEX FULL SCAN     | INX_COMPL_GRP            |       |       |       |       |        |
    |* 12 |    TABLE ACCESS BY INDEX ROWID     | EES_CLINICAL_DATA        |     1 |    33 |       |     1
    |  13 |     NESTED LOOPS                   |                          |  1327 |   196K|       |   947 | 45,13  | PCWP |            |
    |* 14 |      HASH JOIN                     |                          | 60205 |  6996K|       |   495 | 45,13  | PCWP |            |
    |  15 |       TABLE ACCESS BY INDEX ROWID  | EES_CLINCL_COMPL_ICD     |    36 |   756 |       |    
    |* 16 |        INDEX RANGE SCAN            | COMPL_TYPE_TXT_3         |     1 |       |       |     1 |     
    |* 17 |       HASH JOIN                    |                          |  1420K|   132M|       |   494 | 45,13  | PCWP |            |
    |* 18 |        TABLE ACCESS FULL           | EES_ICD_9_CODE           |    37 |  2183 |       |     1 | 45,11 
    |* 19 |        TABLE ACCESS BY INDEX ROWID | EES_CLINICAL_COMPL_DATA  |  4722K|   175M|       |   49
    |  20 |         BITMAP CONVERSION TO ROWIDS|                          |       |       |       |       |        |      |           
    |  21 |          BITMAP INDEX FULL SCAN    | INX_COMPL_GRP            |       |       |       |       |        |
    |* 22 |      INDEX RANGE SCAN              | EES_CLINICAL_DATA_IND1   |     1 |       |       |     2 | 45,13
    |* 23 |    HASH JOIN                       |                          |  2807 |   416K|       |  4695 | 45,13  | PCWP |            |
    |  24 |     TABLE ACCESS FULL              | EES_CLINCL_COMPL_ICD     |   911 | 19131 |       |     2 | 45,06
    |* 25 |     HASH JOIN                      |                          |  2617 |   334K|    15M|  4693 | 45,13  | PCWP |            |
    |* 26 |      TABLE ACCESS FULL             | EES_CLINICAL_DATA        |  1430K|    45M|       |  2855 | 45,07
    |* 27 |      HASH JOIN                     |                          |   791K|    74M|       |   305 | 45,12  | P->P | HASH       |
    |* 28 |       TABLE ACCESS FULL            | EES_ICD_9_CODE           |    37 |  2183 |       |     1 | 45,09 
    |* 29 |       TABLE ACCESS BY INDEX ROWID  | EES_CLINICAL_COMPL_DATA  |  2632K|    97M|       |   30
    |  30 |        BITMAP CONVERSION TO ROWIDS |                          |       |       |       |       |        |    
    |* 31 |         BITMAP INDEX SINGLE VALUE  | INX_COMPL_GRP            |       |       |       |       |        |
    Predicate Information (identified by operation id):
       3 - access("B"."COMPL_ICD_CODE"="D"."ICD_9_CD")
       4 - filter("D"."COMPL_TYPE_TXT"'Intra-operative Misadventure')
       5 - access("B"."ICD_CODE"="C"."ICD_CODE" AND "B"."PAT_KEY"="C"."PAT_KEY")
       6 - filter("C"."PROC_TYPE"'L' AND "C"."DISC_MON">=2003101)
       7 - access("A"."ICD_CODE"="B"."ICD_CODE")
       8 - filter("A"."SPECIALTY"='Colo-Rectal')
       9 - filter("B"."COMPL_ICD_CODE""B"."ICD_CODE")
      11 - filter("B"."COMPL_GRP_TXT"'Reoperations')
      12 - filter("B"."ICD_CODE"="C"."ICD_CODE" AND "C"."PROC_TYPE"'L' AND "B"."PROC_DAY"="C"."PROC_DA
      14 - access("B"."COMPL_ICD_CODE"="D"."ICD_9_CD")
      16 - access("D"."COMPL_TYPE_TXT"='Intra-operative Misadventure')
      17 - access("A"."ICD_CODE"="B"."ICD_CODE")
      18 - filter("A"."SPECIALTY"='Colo-Rectal')
      19 - filter("B"."COMPL_ICD_CODE""B"."ICD_CODE")
      22 - access("B"."PAT_KEY"="C"."PAT_KEY")
      23 - access("B"."COMPL_ICD_CODE"="D"."ICD_9_CD")
      25 - access("B"."ICD_CODE"="C"."ICD_CODE" AND "B"."PAT_KEY"="C"."PAT_KEY")
           filter("B"."PROC_DAY">"C"."PROC_DAY")
      26 - filter("C"."PROC_TYPE"'L' AND "C"."DISC_MON">=2003101)
      27 - access("A"."ICD_CODE"="B"."ICD_CODE")
      28 - filter("A"."SPECIALTY"='Colo-Rectal')
      29 - filter("B"."COMPL_ICD_CODE""B"."ICD_CODE")
      31 - access("B"."COMPL_GRP_TXT"='Reoperations')
    Note: cpu costing is offPlease help.

    Try removing the hints.
    Is 47,000 a reasonable estimate of how many rows you expect in the results?
    See these posts for other information that you should supply.
    HOW TO: Post a SQL statement tuning request
    HOW TO: Post a SQL statement tuning request - template posting
    When your query takes too long
    When your query takes too long ...

  • Tuning an SQL query on a view

    Hi
    I have an SQL that has poor performance when querying a 3 table view.
    I have tried to tune the view by adding an additional index but the EXPLAIN plan does not change.  In fact, the plan is ONLY using fields specified in the the views join conditions and not the WHERE clause.
    I have created an index EKET~Z1 with the column for table (T003)
          EINDT   
    and I have also tried another index EKKO~Z2 with the columns for table T001
          BSART
          BSTYP
          EKORG
    The query is as follows:
    SQL Statement                                                                               
    SELECT                                                                    
        "MANDT" , "EBELN" , "EBELP" , "ETENR" , "EKKO_LOEKZ" , "BSTYP" ,        
        "BSART" , "BUKRS" , "EKORG" , "EKGRP" , "STATU" , "AEDAT" , "ERNAM" ,   
        "BEDAT" , "LIFNR" , "ADRNR" , "WAERS" , "EKPO_LOEKZ" , "EKPO_BSTYP" ,   
        "TXZ01" , "MATNR" , "EMATN" , "WERKS" , "MATKL" , "IDNLF" , "MENGE" ,   
        "MEINS" , "NETPR" , "NETWR" , "PSTYP" , "KNTTP" , "WEPOS" , "ANFNR" ,   
        "PRDAT" , "KONNR" , "KTPNR" , "ELIKZ" , "EREKZ" , "EINDT" , "SLFDT" ,   
        "LPEIN" , "EKET_MENGE" , "EKET_WEMNG" , "BANFN" , "BNFPO" , "MBDAT" ,   
        "WADAT" , "WEBRE" , "FRGRL" , "ZZKONNR" , "ZZKTPNR" , "MAHNZ" ,         
        "MAHN1" , "MAHN2" , "MAHN3" , "INFNR"                                   
      FROM                                                                      
        "ZPO_DETAIL"                                                            
      WHERE                                                                     
        "MANDT" = ? AND "EKORG" = ? AND "BSTYP" = ? AND "BSART" = ? AND         
        "WERKS" = ? AND "EINDT" < ? AND "EKPO_LOEKZ" <> ? AND "ELIKZ" <> ?      
      ORDER BY                                                                  
        "EBELN" , "EBELP" , "ETENR"                                             
    VIEW DETAILS
    CREATE VIEW ZPO_DETAIL          
       (MANDT,                      
       EBELN,                       
       EBELP,                       
       ETENR,                       
       EKKO_LOEKZ,                  
       BSTYP,                       
       BSART,                       
       BUKRS,                       
       EKORG,                       
       EKGRP,                       
       STATU,                       
       AEDAT,                       
       ERNAM,                       
       BEDAT,                       
       LIFNR,                       
       ADRNR,                       
       WAERS,                       
       EKPO_LOEKZ,                  
       EKPO_BSTYP,                  
       TXZ01,                       
       MATNR,                       
       EMATN,                       
    WERKS,              
    MATKL,              
    IDNLF,              
    MENGE,              
    MEINS,              
    NETPR,              
    NETWR,              
    PSTYP,              
    KNTTP,              
    WEPOS,              
    ANFNR,              
    PRDAT,              
    KONNR,              
    KTPNR,              
    ELIKZ,              
    EREKZ,              
    EINDT,              
    SLFDT,              
    LPEIN,              
    EKET_MENGE,         
    EKET_WEMNG,         
    BANFN,              
    BNFPO,              
       MBDAT,        
       WADAT,        
       WEBRE,        
       FRGRL,        
       ZZKONNR,      
       ZZKTPNR,      
       MAHNZ,        
       MAHN1,        
       MAHN2,        
       MAHN3 )       
    AS SELECT        
       T0003."MANDT",
        T0003."EBELN",
        T0003."EBELP",
        T0001."ETENR",
        T0002."LOEKZ",
        T0002."BSTYP",
        T0002."BSART",
        T0002."BUKRS",
        T0002."EKORG",
        T0002."EKGRP",
        T0002."STATU",
        T0002."AEDAT",
       T0002."ERNAM",
       T0002."BEDAT",
       T0002."LIFNR",
       T0002."ADRNR",
       T0002."WAERS",
       T0003."LOEKZ",
       T0003."BSTYP",
       T0003."TXZ01",
       T0003."MATNR",
       T0003."EMATN",
       T0003."WERKS",
       T0003."MATKL",
       T0003."IDNLF",
       T0003."MENGE",
       T0003."MEINS",
       T0003."NETPR",
       T0003."NETWR",
       T0003."PSTYP",
       T0003."KNTTP",
       T0003."WEPOS",
       T0003."ANFNR",
       T0003."PRDAT",
       T0003."KONNR",
        T0003."KTPNR",         
        T0003."ELIKZ",         
        T0003."EREKZ",         
        T0001."EINDT",         
        T0001."SLFDT",         
        T0001."LPEIN",         
        T0001."MENGE",         
        T0001."WEMNG",         
        T0001."BANFN",         
        T0001."BNFPO",         
        T0001."MBDAT",         
        T0001."WADAT",         
        T0003."WEBRE",         
        T0002."FRGRL",         
        T0003."ZZKONNR",       
        T0003."ZZKTPNR",       
        T0003."MAHNZ",         
        T0003."MAHN1",         
        T0003."MAHN2",         
        T0003."MAHN3"          
    FROM                       
       SAPCEP."EKET" T0001,    
        SAPCEP."EKKO" T0002,   
        SAPCEP."EKPO" T0003              
    WHERE                                
        T0002."MANDT" = T0003."MANDT" AND
        T0002."EBELN" = T0003."EBELN" AND
        T0003."MANDT" = T0001."MANDT" AND
        T0003."EBELN" = T0001."EBELN" AND
        T0003."EBELP" = T0001."EBELP"    
    EXPLAIN PLAN
    Execution Plan for SQL Optimizer
                                                                                    TABLENAME     COLUMN OR INDEX                STRATEGY                                     PAGECOUNT                                                                               
    T0003                                                             RANGE CONDITION FOR KEY         15758    
                             MANDT                                         (USED KEY COLUMN)   
    T0001                                                             JOIN VIA MULTIPLE KEY COLUMNS  8632    
                             MANDT                                          (USED KEY COLUMN)                                 
                             EBELN                                           (USED KEY COLUMN)    
    T0002                                                             JOIN VIA MULTIPLE KEY COLUMNS   40109    
                             MANDT                                          (USED KEY COLUMN)                                 
                             EBELN                                           (USED KEY COLUMN)                                 
                             EBELP                                           (USED KEY COLUMN)                                                                               
    NO TEMPORARY RESULTS CREATED                   
    SHOW                                                               RESULT IS COPIED   , COSTVALUE IS   31186  
    SHOW                                                          QUERYREWRITE - APPLIED RULES:                          
                       SHOW                                                             MergeFromSelectOrView                          1                                                                               
    The statistics are up-to-date.
    Any tips would be welcome.
    Thanks
    Doug

    > I have created an index EKET~Z1 with the column for table (T003)
    >       EINDT   
    >
    > and I have also tried another index EKKO~Z2 with the columns for table T001
    >       BSART
    >       BSTYP
    >       EKORG
    >
    SQL Statement                                                               
    >                                                                             
    >   SELECT                                                                    
    >     "MANDT" , "EBELN" , "EBELP" , "ETENR" , "EKKO_LOEKZ" , "BSTYP" ,        
    >   FROM                                                                      
    >     "ZPO_DETAIL"                                                            
    >   WHERE                                                                     
    >     "MANDT" = ? AND "EKORG" = ? AND "BSTYP" = ? AND "BSART" = ? AND         
    >     "WERKS" = ? AND "EINDT" < ? AND "EKPO_LOEKZ" <> ? AND "ELIKZ" <> ?      
    >   ORDER BY                                                                  
    >     "EBELN" , "EBELP" , "ETENR"                                             
    >
    > EXPLAIN PLAN
    > -
    >
    > Execution Plan for SQL Optimizer
    >                                                                               
    > TABLENAME     COLUMN OR INDEX                STRATEGY                                     PAGECOUNT     
    >                                                                               
    > T0003                                                             RANGE CONDITION FOR KEY         15758    
    >                          MANDT                                         (USED KEY COLUMN)   
    >                              
    > T0001                                                             JOIN VIA MULTIPLE KEY COLUMNS  8632    
    >                          MANDT                                          (USED KEY COLUMN)                                 
    >                          EBELN                                           (USED KEY COLUMN)    
    >                             
    > T0002                                                             JOIN VIA MULTIPLE KEY COLUMNS   40109    
    >                          MANDT                                          (USED KEY COLUMN)                                 
    >                          EBELN                                           (USED KEY COLUMN)                                 
    >                          EBELP                                           (USED KEY COLUMN)     
    >                            
    >                                                                          NO TEMPORARY RESULTS CREATED                   
    > SHOW                                                               RESULT IS COPIED   , COSTVALUE IS   31186  
    > SHOW                                                          QUERYREWRITE - APPLIED RULES:                          
    >                    SHOW                                                             MergeFromSelectOrView                          1    
    >                                                                               
    >
    > The statistics are up-to-date.
    > Any tips would be welcome.
    Hi Doug,
    here we go...
    What MaxDB version are you using? Did you check whether the DB parameters all comply to the recommendations?
    If so, what are the cardinalities of the columns you indexed (a.k.a. how many different values do each of them contain?)
    If the specification of BSART,  BSTYP and  EKORG does not reduce the number of rows to be retrieved to a large extent, then the indexaccess is likely to produce additional work.
    Anyhow, the join order looks a bit odd here - this might be the problem caused by having set OPTIMIZE_OPERATOR_JOIN_COSTFUNC = YES in a MaxDB version between 7.6.04 and 7.6.06.
    So make sure it's set to NO (see note 814704 MaxDB Version 7.6 parameter settings for OLTP/BW).
    regards,
    Lars

  • Sql Query to MVC View via LINQ

    I have a Query that is returning the proper results in Sql Server View that runs the query below:
    SELECT        CertificateNumber, COUNT(*) AS LoginCount, InsertDate
    FROM            dbo.LogIns
    GROUP BY CertificateNumber, InsertDate
    Results:
    40050004289468 1
    2015-03-22
    40050004417374 1
    2015-03-22
    40160015050974 1
    2015-03-22
    40250024398851 1
    2015-03-22
    711511 9
    2015-03-22
    90021255342381 6
    2015-03-22
    40060005110838 2
    2015-03-23
    40070006178842 1
    2015-03-23
    40070006216238 1
    2015-03-23
    40070006282800 1
    2015-03-23
    40110010957264 1
    2015-03-23
    40250024090870 1
    2015-03-23
    4045004499703 9 1
    2015-03-23
    711511 13
    2015-03-23
    I am trying to return the same results to an MVC 5 View:
    I imported the view from the db:
    Model:
        public partial class LogInView
            public string CertificateNumber { get; set; }
            public Nullable<int> LoginCount { get; set; }
            public Nullable<System.DateTime> InsertDate { get; set; }
    Controller:
            public ActionResult LoginActivity()
                return View(db.LogInViews.OrderByDescending(i => i.InsertDate).ToList());
    View:
    @model IEnumerable<GCadmin.Models.LogInView>
        ViewBag.Title = "LoginActivity";
    <h2>LoginActivity</h2>
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <table class="table">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.InsertDate)
            </th>
            <th>
                Card Number
            </th>
            <th>
                @Html.DisplayNameFor(model => model.LoginCount)
            </th>
            <th></th>
        </tr>
    @foreach (var item in Model) {
        <tr>
            <td>
                @item.InsertDate.Value.ToShortDateString()
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CertificateNumber)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.LoginCount)
            </td>
        </tr>
    </table>
    Result:
    3/23/2015 40060005110838
    2
    3/23/2015 40070006178842
    1
    3/23/2015 40070006216238
    1
    3/23/2015 40070006282800
    1
    3/23/2015 40110010957264
    1
    3/23/2015 40250024090870
    1
    3/23/2015 4045004499703 9
    1
    3/23/2015 711511
    13
    3/22/2015 40050004289468
    1
    3/22/2015 40050004417374
    1
    3/22/2015 40160015050974
    1
    3/22/2015 40250024398851
    1
    3/23/2015 711511
    13
    3/22/2015 90021255342381
    6
    The 711511 on 3/23 is repeated.
    I cant figure this one out.
    Thanks, Doug

    In the listing of the original query output, might the extra space be part of the issue? (2nd from the last entry). 
    4045004499703 9
    1 2015-03-23

  • Tuning SQL Query calling multiple views

    Dear All,
    I have a complex scenario in which I have created views in 3 levels for sales and Service separately so total no of views are 6.
    Level 2 calls view in Level 1 and Level 3 calls level 2 in sales as well as services.
    Finally Level 4 has the union of sales and Service Level 3 view.
    There are 5 tables used in total and all have been indexed for better performance.
    The cube processing for the above scenario has processing time of 6 mins.
    The goal is to bring it down to 2-3 mins.
    The amount of data currently we are looking at is not more than 2-3 GB.
    Can anybody help me fine tune this scenario?
    Thanks, Franco.

    Run the queries the cube is using in SSMS and turn on the Include Actual Execution Plan option. 
    https://msdn.microsoft.com/en-us/library/ms189562.aspx?f=255&MSPPError=-2147217396
    Straight up it may suggest missing indexes which you can test to see if they improve the query performance.  You can't take these suggestions as gospel - sometimes SQL Server gets it wrong - so you need to test them. 
    After that look in the query plan for any table scan operators.  Unless you are actually retrieving every row in a table you shouldn't have any of these and they can probably be removed by placing a properly considered index on the table. 
    After that look for any RID Lookups or Key Lookups.  These can generally be resolved fairly easily by adding the columns being looked up as "include" columns in the indexes.  
    Here are some links that might get you started.  
    Reading Execution Plans: http://www.mssqltips.com/sqlservertip/1873/how-to-read-sql-server-graphical-query-execution-plans/
    Resolving Table Scans http://blog.sqlauthority.com/2007/03/30/sql-server-index-seek-vs-index-scan-table-scan/
    Resolving Lookups: http://blog.sqlauthority.com/2009/11/09/sql-server-removing-key-lookup-seek-predicate-predicate-an-interesting-observation-related-to-datatypes/
    Those are the obvious things - and generally the easiest to achieve.  Performance tuning is a big area.  It may be that the database queries are already performing perfectly well and the time being spent is processing the cube itself so you need
    to establish where the time is going.  There is no point trying to tune the database queries if they are already working well.
    LucasF

  • Help with sql query on materialized view logs

    I am in need of a query to find out what tablespace and snap shot site a long list of materialized view logs are associated with.
    something like below except tablespace and snap_shot_site are not an option for this table.
    select log_owner, master, log_table, tablespace, snap_shot_site from dba_mview_logs;

    What is the refresh method set as?
    Could you paste the full MV log creation script and the corresponding MV creation script.

  • Check query used to create system views

    Hi Group,
    I would like to know if there is any way to check the TSQL query used by SQL to create system views. I know for user created views, you can open it in Designer or script the view. Use SQL 2012 as an example when selelcting the top 1000 records no underlyng
    query is visible.
    Thanks and Regards,

    You can see most of them using sys.all_objects and sys.system_sql_modules.  For example
    select o.name, m.definition
    from sys.system_sql_modules m
    inner join sys.all_objects o on m.object_id = o.object_id
    where o.name = 'dm_exec_requests'
    Be very careful that you don't ever run the code that creates the view.  There are additional tricks behind the scene that give some system views special actions.  So if you run the code, your code might not work the same way as the original system
    view.
    Also, anything which is not documented can be changed by Microsoft at any time.
    Tom

  • Running a query in a View Designer results in an error, but running the same query in a Query window works

    Hi everyone,
    Just as my title says, I have a query which I've written in a query window and it works perfectly.
    But when I try to add the query code into the view designer, it throws a Syntax error.
    Error in ON clause near '('.Unable to parse query text.
    Also, when running the query from the view designer (pressing red exclamation mark) I get a different error.
    SQL Execution Error.Executed SQL statement: SELECT Sku, ParentSku, UPC, ...Error Source: .Net SqlClient Data ProviderError Message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
    Has anyone else experienced this and is there any workaround?
    I have tried to create the view with T-SQL (CREATE VIEW etc.), but when opening it in the view designer I get the error from the 1st image.
    Thank you,
    Radu

    Hi Radu,
    Yes, I have faced similar issue. I had a View and it was working totally fine but when once I opened it in via right click - View Design, it was giving parse error.
    Cause is that Query designer parse and executes the query without error but the way View designer works, it can't parse it.
    Later I ignored View desinger and just used T-SQL like CREATE/ALTER view.
    Workaround is to do right click on View - Script View as - CREATE To/ ATER To.
    Regarding Timeout error, again the issue with View designer which couldn't execute query in there and ended up with timeout error.
    If your SELECT query and SELECT * FROM YourView works fine in Query designer, you are good to go.
    Similar threads:
    View with errors still saved, and still works...
    Parsing error when creating view
    -Vaibhav Chaudhari

  • Creating materialized view with variables - help

    Greetings,
    I want to create an materialized view (MV) from the external public db link. Below is my full query:
    CREATE MATERIALIZED VIEW PROJECTS_MV
    REFRESH WITH ROWID
    AS
    SELECT prj.Project_id, prj.desc,
    prj.parent_project_id, f_year, f_month
    FROM sysadm.prj@EFUYEEDW_DB_LINK.MSDB prj
    WHERE prj.pf_scenario_id = '708KDD'
    AND prj.ph_id = 'SHAREDP'
    AND f_year = (SELECT EXTRACT(year FROM current_DATE) FROM dual)
    AND f_month = (SELECT EXTRACT(month FROM current_DATE) FROM dual)
    Question: In the query there are two variables that capture the month and year and requery it. Does the data get updated automatically when a new month or new year changes?
    If there is a change, how would I change so it would update the data accordingly?
    Thanks for your help
    john9569

    Hi Christian,
    Thanks for your response. Your codes return the date as 01-JAN-09 which is not what I'm looking for. Maybe my question is not clear.
    So far, the MV is executed correctly what I want. My concern is when it updates the MV, does it get the new data (f_month & f_year) when the MV is updated automatically?
    Other words, the MV is updated nightly to get the incremental data from the db link. Once it passes to the new month, I am not sure how this MV handles since the f_month is now changed to differrent number.
    Thanks for your help.
    Bests,
    John9569

  • Create Materialized view Error ORA-22818

    Hi,
    I am creating a materialized view based on a complex query with inline queries, below is a simplified version of the query:
    CREATE MATERIALIZED VIEW CM_FA_PEND_mvu
    TABLESPACE CISTS_TH
    BUILD IMMEDIATE
    REFRESH COMPLETE
    ENABLE QUERY REWRITE
    AS
    SELECT/*+ index (a,XT094S3) index (b,XT232S1) index (c, XM143P0) index (d, XM185S1)*/
    a .fa_id,
    a.fa_type_cd,
    a.fa_status_flg,
    a.disp_grp_cd,
    (SELECT dl.descr
    FROM ci_disp_grp_l dl
    WHERE dl.disp_grp_cd = a.disp_grp_cd AND dl.language_cd = 'ENG')
    disp_grp_cd_descr
    FROM ci_fa a,
    ci_sp_mtr_hist b,
    ci_mtr_config c,
    ci_reg d,
    ci_fapr_faty e
    WHERE a.fa_type_cd = e.fa_type_cd
    AND a.sp_id = b.sp_id(+)
    AND b.mtr_config_id = c.mtr_config_id(+)
    AND c.mtr_id = d.mtr_id(+)
    AND a.fa_status_flg = 'P'
    AND e.fa_type_prof_cd = 'METERED'
    AND ( (b.removal_dttm IS NULL))
    I am getting error "ORA-22818: subquery expressions not allowed here". the problem is in columns "disp_grp_cd_descr" (when I remove this column from the query, the MView is created successfully)
    Is using inline queries as columns a limitation on creating materialized view?
    Is there a workaround ?
    Thanks
    AK

    No version and no exception ... the full text is necessary the number alone insufficient ... to help you much other than recommend you read this:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10810/basicmv.htm#DWHSG8195
    where it says:
    "The SELECT clause in the materialized view creation statement defines the data that the materialized view is to contain. Only a few restrictions limit what can be specified. Any number of tables can be joined together. Besides tables, other elements such as views, inline views (subqueries in the FROM clause of a SELECT statement), subqueries, and materialized views can all be joined or referenced in the SELECT clause. You cannot, however, define a materialized view with a subquery in the SELECT list of the defining query. You can, however, include subqueries elsewhere in the defining query, such as in the WHERE clause."
    Something you could have found in a second or two in the docs at http://tahiti.oracle.com by searching for "Materialized Views Restrictions"
    But without your version and the actual error message this may not apply.

  • How to get sql query data and write into csv file?

    I am writing to seek help, in how can I create bat. script which can execute the following logic:
    connection to the database
    run sql query
    create CSV file
    output query data, into CSV file
    save the CSV file
    osql
    -S 84.18.111.111
    -U adw
    -P rem
    -i "c:\query.sql"
    send ""
    sed -e 's/,\s\+/,/g' MCI_04Dec2014.csv > localNoSpaces.csv
    -o "c:\MCI_04Dec2014.csv"
    This what i have so far, and I am little struggling with the logic after creating CSV file. I am unable to get the above script to work, please advice further, where I may be going wrong. 
    Can you create if statement logic within window's script, to check for null parameters or data feeds?
    Any hints would be most appreciated. 

    Thank you for your reply. 
    Apology for posting the code irrelevant to the forum, as I am still novice scripting user.  
    My goal is to create window's script which can compute the above logic and send the final output file (csv), to FTP folder. 
    Can this logic be implemented via bat. script, if so, is there a example or tutorial i could follow, in order to achieve my task. 
    Any help would be much appreciated. 

Maybe you are looking for

  • Transfer music from one Ipod to another

    I have an I Pod Mini and now also a shuffle. I would like to transfer the songs from the mini to the shuffle on ITunes but it doesn't work. Does anyone know how I can do that ? Thanks

  • HARD DISK PROBS / TIME MACHINE not behaving with TC ? READ THIS!!!!

    I had many probs with the hard disk and now have a happy healthy TC working great with time machine, so I though I'd share my experiences with others hoping it will save you my huge pain ! i, I've spent hours and hours trying to get the harddisk to w

  • Dual Thunderbolt displays on Macbook Pro

    I have a 15" MacBook Pro (mid-2011) with two 27" Thunderbolt displays. I very frequently boot my Macbook (laptop closed) and my two displays are out of order. I always know it's a problem because one of my wallpapers get's changed. It sometimes takes

  • Does anybody know how to report a problem on an app that had been purchased over 90 days ago

    I wanted to know how to report a problem on an app that i purchased over 90 days ago the only thing i can view is the apps i have purchased within 90 days.

  • Use fwrite function in LKM at 64 bit

    I have a problem with an LKM module. I have done a module at 64 bit , and i have used fwrite and lseek function in this module , but when i use modload command to load the module in kernel i have this response : krtld : undefined symbols ' lseek ' kr