Query pain - need help

Hi @ll,
i got this query, but it does not work. Any idea ?
DECLARE @xyz nvarchar(1)
SELECT @xyz =  (SELECT T0.TreeType FROM OITM T0 WHERE T0.ItemCode = [%1])
SELECT CASE @xyz <> 'S' THEN '1' ELSE '2' END
Thanks Steffen

You have left a 'When'. Try this:
DECLARE @xyz nvarchar(1)
SELECT @xyz =  (SELECT T0.TreeType FROM OITM T0 WHERE T0.ItemCode = [%1])
SELECT CASE @xyz When  'S' THEN '1' ELSE '2' END

Similar Messages

  • Query problem - need help

    Hi everyone,
    I need some help from you because before I update my View Object I need to know one value using a Query like this: SELECT cp FROM cpostais WHERE cp4=1234 AND cp3 = 123. The result of the Query I need to save it on a variable (let's call CP) so I can use it to update my View Object. Something like this: currentRow.setAttribute("CPostal", CP);
    I'm using JDeveloper 10.1.2, struts and UIX pages.
    Can anyone tell me how can I do this? I need an example or a tutorial.
    This is really importante, can anyone help me??
    Thanks,
    Atena
    Message was edited by:
    Atena

    I tried to use something like this:
    ViewObject thirdView = daContext.getBindingContext().getDefaultDataControl().getApplicationModule().findViewObject("S2CodigosPostaisView1");
    thirdView.setWhereClauseParam(0, currentRow1.getAttribute("Localidade"));
    thirdView.setWhereClauseParam(1, currentRow1.getAttribute("Cp"));
    thirdView.setWhereClauseParam(2, currentRow1.getAttribute("Ext"));
    thirdView.executeQuery();
    Row currentRow3 = thirdView.getCurrentRow();
    currentRow3.getAttribute("Id");
    But this is not working. :(
    Can anyone help me with this????
    Thanks,
    Atena
    Message was edited by:
    Atena

  • Query Designer: Need help.

    Hi All,
    This is regarding query issue.
    Is this the right forum for this issue or is there a forum for that?
    Kindly tell me where should i post this kind of issue.
    BTW, below is my issue. I'm finding it hard resolving the defect.
    Needs advice on this issue.
    The user wants a record for a certain organization.
    He/she input all the required parameters.
    Let's say:
    Business leader ID: XXX01
    Begin date: 2010, 2011
    End date: 2010, 2011
    Status: Active
    After executing the report, it returns all of the necessary data records.
    But when he click on variable screen or change selection, then changes "ONLY" the Business leader ID.
    It goes:
    Business leader ID: XXY02
    Begin date: 2010, 2011
    End date: 2010, 2011
    Status: Active
    No Applicable Data were returned.
    User closes the report the reopen.
    He initially entered again with the second ID, parameters now are initially:
    Business leader ID: XXY02
    Begin date: 2010, 2011
    End date: 2010, 2011
    Status: Active
    Then necessary records were returned.
    Question: why is it not returning any data records when he/she change the Business leader ID?
    That problem arises only when Business Leader ID was being changed.
    But when he/she change selection and change the filter on Begin Date, End Date, Status, the report still provide the data.
    The report is not refreshing only when Business Leader ID was being changed.
    Thanks!

    Hi,
    You have to check it in your Bex Designer what kind of filter have given report.  I think the variable which are user entering the value in the initial screen which may for hard filter. 
    Open your query in designer and give the details of Variable screen would be very much easy to identify the issue. 
    Just try this
    V1 is the variable for  Business leader ID: XXX01  
    V2 is the variable for  Begin date: 2010, 2011
    V3 is the variable for  End date: 2010, 2011
    V4 is the variable for  Status: Active
    Except V1 variable all can be included in hard filter and Include V1 as restriction. 
    Hope this will help you to close the issue .. if you need any further assistance , please give the screen shot of your report in bex designer.
    Thanks
    BVR

  • Select Query Problem-need help

    hi,
    Help me out from this problem.
    Actually i have a table and the data in it as follows:
    Department Name Job Name
    Accounts Sr. Accountant
    Accounts Jr. Accountant
    Accounts Cleark
    But i dont want the repeated Department Name.. and i want the same output as follows.
    Department Name Job Name
    Accounts Sr. Accountant
    Jr. Accountant
    Cleark
    Without using sql reports and Sql Plus additional commands.
    The same output should come from a sql query only.
    Thanks in Advance
    Md Anwer Ali

    I shouldn't try to code before I have had at least three cups of coffee. The actual answer is:
    select decode(department,lag(department) over (order by department),null,department)
    , job
    from departments
    order by department.
    I ran this:
    select decode(job,lag(job) over (order by job),null,job)
    , ename
    from emp
    order by job
    and got this result:
    SQL> /
    DECODE(JO ENAME
    ANALYST SCOTT
    FORD
    CLERK SMITH
    ADAMS
    MILLER
    JAMES
    MANAGER JONES
    CLARK
    BLAKE
    PRESIDENT KING
    SALESMAN ALLEN
    MARTIN
    TURNER
    WARD
    14 rows selected.

  • Simple sum query I need help with please

    I need a query to do something like this:
    select customer_site_use_id
    from ar_payment_schedules_all ps
    where ps.status = 'OP'
    AND NVL(ps.receipt_confirmed_flag,'Y') = 'Y'
    and exists (select (sum(ps1.acctd_amount_due_remaining) as amtdue)
    from ar_payment_schedules_all ps1
    where ps1.customer_site_use_id = ps.customer_site_use_id
    and amtdue < 0)
    and ps.customer_site_use_id = 1593
    I may be making this too difficult. I don't know if I need the exists clause and the second select statement. In the exists statement, if the sum of all of the acctd_amount_due_remaining in ar_payment_schedules_all for the same customer_site_use_id is less than 0, then it is in the results.

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using.
    I'm pretty sure you don't want an EXISTS sub-query. EXISTS returns TRUE if the sub-query finds any rows; it doesn't matter how many, or what's on them.
    Perhaps you want something like this:
    WITH     got_total_amount_due     AS
         SELECT       customer_site_use_id
         ,       SUM (acctd_amount_due)     AS total_amount_due
         FROM       ar_payment_schedules_all
         GROUP BY  customer_site_use_id
    SELECT    ps.customer_site_use_id
    FROM        ar_payment_schedules_all     ps
    JOIN       got_total_amount_due          td  ON  ps.customer_site_use_id  = td.customer_site_use_id
    WHERE       ps.status            = 'OP'
    AND       NVL ( ps.receipt_confirmed_flag
               , 'Y'
               )                 = 'Y'
    AND        ps.customer_site_use_id = 1593
    AND       td.total_amount_due       < 0
    ;That gives you access to the total amount for each customer_site_id

  • Problem with a query i need help ;(

    hi all guys!!! i have this query:
    SELECT SII_PLAACCIO.TITOL AS "PLA_TITLE" ,JBPM_PROCESSINSTANCE.ID_ AS "PROC_INST",SII_ACCIO_ORG_RESP.NOM AS "RESP_TITLE" ,SII_EIX.NOM AS "EIX_TITLE" ,
    REPTE.DESCRIPCIO AS "REPT_TITLE",SII_PROGRAMA.TITOL AS "PRG_TITLE" ,SII_ACCIO.TITOL AS "ACC_TITLE",PROJECTE.DESCRIPCIO AS "PROY_TITLE",ESTAT.DESCRIPCIO AS "ACC_STATUS", DEPARTAMENT.DESCRIPCIO AS "DEPARTAMENT",
    ROUND(SII_PRESSUPOST.TOTAL_EXECUTAT,'2') AS FON_SPENDED, ROUND(SII_PRESSUPOST.TOTAL_ASSIGNAT,'2') AS FON_BUDGET
    FROM SII_ACCIO
    ACTUACIO
    LEFT JOIN JBPM_PROCESSINSTANCE ON SII_ACCIO.PROCESS_INSTANCE_ID = JBPM_PROCESSINSTANCE.ID_
    LEFT JOIN JBPM_TOKEN ON JBPM_PROCESSINSTANCE.ROOTTOKEN_ = JBPM_TOKEN.ID_
    LEFT JOIN JBPM_NODE ON JBPM_TOKEN.NODE_ = JBPM_NODE.ID_
    INNER JOIN SII_MESTRE ESTAT ON (JBPM_NODE.NAME_ = ESTAT.VALOR AND ESTAT.TIPUS = 'EWF')
    LEFT JOIN SII_PRESSUPOST ON SII_ACCIO.PRESSUPOST = SII_PRESSUPOST.ID
    LEFT JOIN sii_accio_ORG_RESP ON SII_ACCIO.ID = SII_ACCIO_ORG_RESP.ACCIO_ID
    LEFT JOIN SII_MESTRE DEPARTAMENT ON (SII_ACCIO_ORG_RESP.DEPARTAMENT_ID = DEPARTAMENT.ID AND DEPARTAMENT.TIPUS = 'DEP')
    PROJECTE
    LEFT JOIN SII_MESTRE PROJECTE ON (SII_ACCIO.PROJECTE_ID = PROJECTE.ID AND PROJECTE.TIPUS = 'PRJ')
    PROGRAMA
    LEFT JOIN SII_PROGRAMA ON SII_ACCIO.PROGRAMA_ANUAL = SII_PROGRAMA.ID
    REPTE
    LEFT JOIN SII_MESTRE REPTE ON (SII_PROGRAMA.REPTE_ID = REPTE.ID AND REPTE.TIPUS = 'REP')
    EIX
    LEFT JOIN SII_EIX ON SII_PROGRAMA.EIX_ANUAL = SII_EIX.ID
    PLA ACTUACIO
    LEFT JOIN SII_PLAACCIO ON SII_EIX.PLA_ACCIO = SII_PLAACCIO.ID
    the problem is the following: the column "JBPM_PROCESSINSTANCE.ID_" can contain duplicate entries, but in the result i just want one of the rows... it doesn't matter which one, i just want only one...
    i can't use distinct and group by,.., i've been trying for the last 2 days almost but i cannot find a solution..

    But if don't want to use group by:
    select * from (
    SELECT SII_PLAACCIO.TITOL AS "PLA_TITLE" ,min(JBPM_PROCESSINSTANCE.ID_) AS "PROC_INST",SII_ACCIO_ORG_RESP.NOM AS "RESP_TITLE" ,SII_EIX.NOM AS "EIX_TITLE" ,
      REPTE.DESCRIPCIO AS "REPT_TITLE",SII_PROGRAMA.TITOL AS "PRG_TITLE" ,SII_ACCIO.TITOL AS "ACC_TITLE",PROJECTE.DESCRIPCIO AS "PROY_TITLE",ESTAT.DESCRIPCIO AS "ACC_STATUS", DEPARTAMENT.DESCRIPCIO AS "DEPARTAMENT",
    ROUND(SII_PRESSUPOST.TOTAL_EXECUTAT,'2') AS FON_SPENDED, ROUND(SII_PRESSUPOST.TOTAL_ASSIGNAT,'2') AS FON_BUDGET,
    row_number() over (partition by SII_PLAACCIO.TITOL ,SII_ACCIO_ORG_RESP.NOM ,SII_EIX.NOM ,
      REPTE.DESCRIPCIO,SII_PROGRAMA.TITOL ,SII_ACCIO.TITOL,PROJECTE.DESCRIPCIO,ESTAT.DESCRIPCIO, DEPARTAMENT.DESCRIPCIO,
    ROUND(SII_PRESSUPOST.TOTAL_EXECUTAT,'2'), ROUND(SII_PRESSUPOST.TOTAL_ASSIGNAT,'2') order by rownum) rn
       FROM SII_ACCIO
         --ACTUACIO--
         LEFT JOIN JBPM_PROCESSINSTANCE ON SII_ACCIO.PROCESS_INSTANCE_ID =  JBPM_PROCESSINSTANCE.ID_
         LEFT JOIN JBPM_TOKEN ON JBPM_PROCESSINSTANCE.ROOTTOKEN_ = JBPM_TOKEN.ID_
         LEFT JOIN JBPM_NODE ON JBPM_TOKEN.NODE_ = JBPM_NODE.ID_
         INNER JOIN SII_MESTRE ESTAT ON (JBPM_NODE.NAME_ = ESTAT.VALOR AND ESTAT.TIPUS = 'EWF')
         LEFT JOIN SII_PRESSUPOST ON SII_ACCIO.PRESSUPOST = SII_PRESSUPOST.ID
         LEFT JOIN sii_accio_ORG_RESP ON SII_ACCIO.ID = SII_ACCIO_ORG_RESP.ACCIO_ID
         LEFT JOIN SII_MESTRE DEPARTAMENT ON (SII_ACCIO_ORG_RESP.DEPARTAMENT_ID = DEPARTAMENT.ID AND DEPARTAMENT.TIPUS = 'DEP')
         --PROJECTE--
         LEFT JOIN SII_MESTRE PROJECTE ON (SII_ACCIO.PROJECTE_ID = PROJECTE.ID AND PROJECTE.TIPUS = 'PRJ')
         --PROGRAMA--
         LEFT JOIN SII_PROGRAMA ON SII_ACCIO.PROGRAMA_ANUAL = SII_PROGRAMA.ID
         --REPTE--
         LEFT JOIN SII_MESTRE REPTE ON (SII_PROGRAMA.REPTE_ID = REPTE.ID AND REPTE.TIPUS = 'REP')
         --EIX--
         LEFT JOIN SII_EIX ON SII_PROGRAMA.EIX_ANUAL = SII_EIX.ID
         --PLA ACTUACIO--
         LEFT JOIN SII_PLAACCIO ON SII_EIX.PLA_ACCIO = SII_PLAACCIO.ID
    ) where rn=1Max
    http://oracleitalia.wordpress.com

  • Simple SQL query..need help

    Hi All,
    I have a requirement not to show the row, if all columns value is zero. Could someone help me how to do it?
    For example:
    A     B     C   D    E
    1 1 5 1 2
    1 0 5 0 2
    0 9 7 1 0
    0 0 0 0 0
    From the above example the only last row should not be shown, because all columns value is zero.
    Thanks in advance.

    Another way:
    with abc as (select 1 a, 1 b, 5 c, 1 d, 2 e from dual union all
                 select 1 a, 0 b, 5 c, 0 d, 2 e from dual union all
                 select 0 a, 9 b, 7 c, 1 d, 0 e from dual union all
                 select 0 a, 0 b, 0 c, 0 d, 0 e from dual union all
                 select null a, 0 b, 0 c, 0 d, 0 e from dual)
    select a, b, c, d, e
    from   abc
    where  (nvl(a, 0), nvl(b, 0), nvl(c, 0), nvl(d, 0), nvl(e, 0)) not in (select 0,0,0,0,0 from dual);
             A          B          C          D          E
             1          1          5          1          2
             1          0          5          0          2
             0          9          7          1          0

  • af:query component - need help

    hi
    I am implemeting a search page wiht <af:query> component with view criteria. (to be specific drag and drop viewCriteria as query panel with table)
    what i observe is that when I do "Add fields" at runtime the compnent moves up and up till it hides the panelHeader and the other fields with no access to it.
    After i refresh the screen the component comes back to its normal positon but pushes the table component below it down till its barely visible.
    This component seems to be very unstable.
    Let me know if there is any workaround without making the screen unstable.

    Hi,
    You can find some related info here..
    Can I achive valueChangeListener in af:query?
    and
    http://jobinesh.blogspot.com/2011/03/retrieving-viewcriteria-from-custom.html
    Thanks,
    TK

  • MDX query..need help

    Hi experts..
    I have written a MDX query as follows:
    alter session set dml_output alias off ;
    spool stdout on to 'C:\ACCT_110711.TXT';
    SELECT {} ON AXIS(0), {[Year].Members} ON AXIS(1) FROM [CUBE];
    spool off;
    This is generating a txt file with the whole output - including the query I put and the "Statement executed successfully" message.
    What do I have to do to get just the output in a file. Is it possible in Essbas..or do I have to manipulate the file using unix or something after the generation.

    The output from spooling to a file using Maxl is not the best, MDX is not really the equivalent of report scripts.
    You could look at parsing the file after it is generated, or maybe look at perl or an API or ODI or report scripts to generate it in a cleaner format.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Sql query tunning, need help!

    below is the sql that runs very very slow:
    SELECT h.STAT_HIST_ID, h.WF_ACTN, h.USR_ACTN,
          h.WF_CHNG_DATA, h.USR_CHNG_DATA, h.PRCSG_TM, h.UPD_LOGIN, h.UPD_DT,
          RTRIM(c.LAST_NM || ', ' || c.FIRST_NM || ' ' || c.MIDDLE_INITIAL)
          FROM WF_STAT_HIST h, CSE_USER_DATA_VW c WHERE h.WRK_ITM_ID = 'GT1MPTG01ATBZP'
          AND h.UPD_LOGIN = c.USER_NM (+) ORDER BY h.UPD_DT ;Here is its index:
    all_indexes:
    SCGDBA     WF_STAT_HIST_INDX_ARCH     NORMAL     SCGDBA     WF_STAT_HIST     TABLE     NONUNIQUE     DISABLED          IMS_I
    SCGDBA     PK_WF_STAT_HIST     NORMAL     SCGDBA     WF_STAT_HIST     TABLE     UNIQUE     DISABLED          SCG_I
    SCGDBA     WF_STAT_HIST_IDX1     NORMAL     SCGDBA     WF_STAT_HIST     TABLE     NONUNIQUE     DISABLED          SCG_I
    all_ind_columns:
    SCGDBA     WF_STAT_HIST_INDX_ARCH     SCGDBA     WF_STAT_HIST     ARCHIVEDT     1     7     0     ASC
    SCGDBA     PK_WF_STAT_HIST     SCGDBA     WF_STAT_HIST     STAT_HIST_ID     1     22     0     ASC
    SCGDBA     WF_STAT_HIST_IDX1     SCGDBA     WF_STAT_HIST     WF_ACTN     1     50     50     ASC
    SCGDBA     WF_STAT_HIST_IDX1     SCGDBA     WF_STAT_HIST     USR_ACTN     2     50     50     ASCHere is its explain plan:
    Plan hash value: 479056202
    | Id  | Operation           | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |                  |   216 | 30456 | 70864   (2)| 00:14:11 |
    |   1 |  SORT ORDER BY      |                  |   216 | 30456 | 70864   (2)| 00:14:11 |
    |*  2 |   HASH JOIN OUTER   |                  |   216 | 30456 | 70863   (2)| 00:14:11 |
    |*  3 |    TABLE ACCESS FULL| WF_STAT_HIST     |   216 | 24840 | 70857   (2)| 00:14:11 |
    |   4 |    TABLE ACCESS FULL| CSE_USER_DATA_VW |  1013 | 26338 |     6   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("H"."UPD_LOGIN"="C"."USER_NM"(+))
       3 - filter("H"."WRK_ITM_ID"='GT1MPTG01ATBZP')Could you guys take a look and tell me what the problem might be?
    I can`t give you TKPROF, because I got no access to that trace files!
    Any thoughts would be appreciated:-)
    Edited by: PhoenixBai on Sep 27, 2009 3:13 PM

    Pl post the output of the following
    select count(*) from wf_stat_hist;
    select count (distinct wrk_itm_id) from wf_stat_hist;
    select count (distinct upd_login) from wf_stat_hist;Your code is performing poorly because your WHERE clause is searching on a column on WF_STAT_HIST that is not indexed. Hopefully the output of the above code will determine which column (WRK_ITM_ID or UPD_LOGIN) is a better candidate to be indexed on. If neither of these columns is a good candidate, you may have to change the WHERE clause to be more selective rather than do a full table scan as the plan indicates.
    HTH
    Srini

  • Need help with INSERT and WITH clause

    I wrote sql statement which correctly work, but how i use this statment with INSERT query? NEED HELP. when i wrote insert i see error "ORA 32034: unsupported use of with clause"
    with t1 as(
    select a.budat,a.monat as period,b.vtweg,
    c.gjahr,c.buzei,c.shkzg,c.hkont, c.prctr,
    c.wrbtr,
    c.matnr,
    c.menge,
    a.monat,
    c.zuonr
    from ldw_v1.BKPF a,ldw_v1.vbrk b, ldw_v1.bseg c
    where a.AWTYP='VBRK' and a.BLART='RV' and a.BUKRS='8431' and a.awkey=b.vbeln
    and a.bukrs=c.bukrs and a.belnr=c.belnr and a.gjahr=c.gjahr and c.koart='D'
    and c.ktosl is null and c.gsber='4466' and a.gjahr>='2011' and b.vtweg='01'
    ,t2 as(
    select a.BUKRS,a.BELNR, a.GJAHR,t1.vtweg,t1.budat,t1.monat from t1, ldw_v1.bkpf a
    where t1.zuonr=a.xblnr and a.blart='WL' and bukrs='8431'
    ,tcogs as (
    select t2.budat,t2.monat,t2.vtweg, bseg.gjahr,bseg.hkont,bseg.prctr,
    sum(bseg.wrbtr) as COGS,bseg.matnr,bseg.kunnr,sum(bseg.menge) as QUANTITY
    from t2, ldw_v1.bseg
    where t2.bukrs=bseg.bukrs and t2.belnr=bseg.BELNR and t2.gjahr=bseg.gjahr and BSEG.KOART='S'
    group by t2.budat,t2.monat,t2.vtweg, bseg.gjahr,bseg.hkont,bseg.prctr,
    bseg.matnr,bseg.kunnr
    ,t3 as
    select a.budat,a.monat,b.vtweg,
    c.gjahr,c.buzei,c.shkzg,c.hkont, c.prctr,
    case when c.shkzg='S' then c.wrbtr*(-1)
    else c.wrbtr end as NTS,
    c.matnr,c.kunnr,
    c.menge*(-1) as Quantity
    from ldw_v1.BKPF a,ldw_v1.vbrk b, ldw_v1.bseg c
    where a.AWTYP='VBRK' and a.BLART='RV' and a.BUKRS='8431' and a.awkey=b.vbeln
    and a.bukrs=c.bukrs and a.belnr=c.belnr and a.gjahr=c.gjahr and c.koart='S'
    and c.ktosl is null and c.gsber='4466' and a.gjahr>='2011' and b.vtweg='01'
    ,trevenue as (
    select t3.budat,t3.monat,t3.vtweg, t3.gjahr,t3.hkont,t3.prctr,
    sum(t3.NTS) as NTS,t3.matnr,t3.kunnr,sum(t3.QUANTITY) as QUANTITY
    from t3
    group by t3.budat,t3.monat,t3.vtweg, t3.gjahr,t3.hkont,t3.prctr,t3.matnr,t3.kunnr
    select NVL(tr.budat,tc.budat) as budat,
    NVL(tr.monat,tc.monat) as monat,
    NVL(tr.vtweg,tc.vtweg) as vtweg,
    NVL(tr.gjahr, tc.gjahr) as gjahr,
    tr.hkont as NTS_hkont,
    tc.hkont as COGS_hkont,
    NVL(tr.prctr,tc.prctr) as prctr,
    NVL(tr.MATNR, tc.MATNR) as matnr,
    NVL(tr.kunnr, tc.kunnr) as kunnr,
    NVL(tr.Quantity, tc.Quantity) as Quantity,
    tr.NTS as NTS,
    tc.COGS as COGS
    from trevenue TR full outer join tcogs TC
    on TR.BUDAT=TC.BUDAT and TR.MONAT=TC.MONAT and TR.GJAHR=TC.GJAHR
    and TR.MATNR=TC.MATNR and TR.KUNNR=TC.KUNNR and TR.QUANTITY=TC.QUANTITY
    and TR.VTWEG=TC.VTWEG and TR.PRCTR=TC.PRCTR
    Edited by: user13566113 on 25.03.2011 5:26

    Without seeing what you tried it is hard to say what you did wrong, but this is how it would work
    SQL> create table t ( n number );
    Table created.
    SQL> insert into t
      2  with test_data as
      3    (select 1 x from dual union all
      4     select 2 x from dual union all
      5     select 3 x from dual union all
      6     select 4 x from dual)
      7  select x from test_data;
    4 rows created.
    SQL>

  • Need Help in Splitting a String Using SQL QUERY

    Hi,
    I need help in splitting a string using a SQL Query:
    String IS:
    AFTER PAINT.ACOUSTICAL.1..9'' MEMBRAIN'I would like to seperate this string into multiple lines using the delimeter .(dot)
    Sample Output should look like:
    SNO       STRING
    1            AFTER PAINT
    2            ACOUSTICAL
    3            1
    4            
    5            9" MEMBRAIN
    {code}
    FYI i am using Oracle 9.2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    There's this as well:
    with x as ( --generating sample data:
               select 'AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN' str from dual union all
               select 'BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN' str from dual)
    select str,
           row_number() over (partition by str order by rownum) s_no,
           cast(dbms_xmlgen.convert(t.column_value.extract('//text()').getstringval(),1) as varchar2(100)) res
    from x,
         table(xmlsequence(xmltype('<x><x>' || replace(str,'.','</x><x>') || '</x></x>').extract('//x/*'))) t;
    STR                                                S_NO RES                                                                                                
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 1 AFTER PAINT                                                                                        
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 2 ACOUSTICAL                                                                                         
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 3 1                                                                                                  
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 4                                                                                                    
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 5 9" MEMBRAIN                                                                                        
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          1 BEFORE PAINT                                                                                       
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          2 ELECTRIC                                                                                           
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          3 2                                                                                                  
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          4                                                                                                    
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          5 45 caliber MEMBRAIN      
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need help in rewriting a sql query

    Can any one please tell me if there is any utility that can help me correcting the sql I have I need to tune the query as its taking lot of time. I want to use some tool that will help me re-formating the query.
    Any help in this regard will be highly appreciated.

    If you think that Oracle SQL Tuning Tools like SQL Tuning Advisor and SQL Access Advisor are not helping.
    You might look into thrid party tools like Quest- SQL Navigator and TOAD.
    But I don't advise this based on the following:
    Re: Oracle Third Party Tools and Oracle Database
    Oracle have enough tools of its own to satisfy the various needs.
    Adith

  • Need help with conditional query

    guys this is just an extension of this post that Frank was helping me with. im reposting because my requirements have changes slightly and im having a hell of a time trying to modify the query.
    here is the previous post.
    need help with query that can look data back please help.
    CREATE TABLE "FGL"
        "FGL_GRNT_CODE" VARCHAR2(60),
        "FGL_FUND_CODE" VARCHAR2(60),
        "FGL_ACCT_CODE" VARCHAR2(60),
        "FGL_ORGN_CODE" VARCHAR2(60),
        "FGL_PROG_CODE" VARCHAR2(60),
        "FGL_GRNT_YEAR" VARCHAR2(60),
        "FGL_PERIOD"    VARCHAR2(60),
        "FGL_BUDGET"    VARCHAR2(60)
      )data
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');
    I need to find the greatest grant year for the grant by a period parameter.
    once i find the greatest year i need to check the value of period 14 for that grant for the previous year and add it to the budget amount for that grant. however if their is an entry in the greatest year for period 00 then i need to ignore the period 14 of previous year and do this calculation current period +(current period - greatest year 00)
    hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
    because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
    period 2 amount $ 600
    period 0 amount $ 400 - period 2 amount of $600 = 200
    600+200 = $800
    if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
    i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
    can you please help me out.
    here is the query supplied by frank kulash who gracefully put this together for me.
    WITH     got_greatest_year     AS
         SELECT     fgl.*     -- or whatever columns are needed
         ,     MAX ( CASE
                     WHEN  fgl_period = :given_period
                     THEN  fgl_grnt_year
                    END
                  ) OVER ()     AS greatest_year
         FROM     fgl
    SELECT     SUM (fgl_budget)     AS total_budget     -- or SELECT *
    FROM     got_greatest_year
    WHERE     (     fgl_grnt_year     = greatest_year
         AND     fgl_period     = :given_period
    OR     (     fgl_grnt_year     = greatest_year - 1
         AND     fgl_period     = 14
    ;Miguel

    Hi, Miguel,
    Are you waying that, when the greatest year that has :given_period also has period='00' (or '0', or whatever you want to use), then you want to double the budget from the given_period (as well as subtract the budget from the '00', and not count the pevious year's '14')? If so, add another condition to the CASE statement which decides what you're SUMming:
    WITH     got_greatest_year     AS
         SELECT       TO_NUMBER (fgl_grnt_year)     AS grnt_year
         ,       fgl_period
         ,       TO_NUMBER (fgl_budget)     AS budget
         ,       MAX ( CASE
                       WHEN  fgl_period = :given_period
                       THEN  TO_NUMBER (fgl_grnt_year)
                      END
                    ) OVER ()     AS greatest_year
         FROM       fgl
    ,     got_cnt_00     AS
         SELECT     grnt_year
         ,     fgl_period
         ,     budget
         ,     greatest_year
         ,     COUNT ( CASE
                       WHEN  grnt_year     = greatest_year
                       AND       fgl_period     = '00'
                       THEN  1
                         END
                    ) OVER ()          AS cnt_00
         FROM    got_greatest_year
    SELECT       SUM ( CASE
                        WHEN  grnt_year     = greatest_year                    -- New
                  AND       fgl_period     = :given_period                    -- New
                  AND       cnt_00     > 0            THEN  budget * 2     -- New
                        WHEN  grnt_year     = greatest_year
                  AND       fgl_period     = :given_period       THEN  budget
                        WHEN  grnt_year     = greatest_year
                  AND       fgl_period     = '00'            THEN -budget
                        WHEN  grnt_year     = greatest_year - 1
                  AND       fgl_period     = '14'     
                  AND       cnt_00     = 0            THEN  budget
                    END
               )          AS total_budget
    FROM       got_cnt_00
    ;You'll notice this is the same as the previous query I posted, except for 3 lines maked "New".

  • Need help with Query

    Hi,
    Good day everyone! I need help writing a query. I have this table with the following data in them...
    ACCT_CODE  FSYR      YTD_AMT
    A123            11          100  
    A456            11          200
    A123            10          50
    A456            10          100I want the output to look like this:
    ACCT_CODE     CURRENT_YEAR(11)       PRIOR_YEAR(10)
    A123               100                              50
    A456               200                              100The user will input the fiscal year and based on that input, I want to get the prior year value as well.
    Thank you for all your help!!
    Edited by: user5737516 on Jun 29, 2011 6:48 AM
    Edited by: user5737516 on Jun 29, 2011 6:50 AM

    user5737516 wrote:
    Hi,
    Good day everyone! I need help writing a query. I have this table with the following data in them...
    ACCT_CODE FSYR YTD_AMT
    A123 11 100
    A456 11 200
    A123 10 50
    A456 10 100
    I want the output to look like this:
    ACCT_CODE CURRENT_YEAR PRIOR_YEAR
    A123 100 50
    A456 200 100
    The user will input the fiscal year and based on that input, I want to get the prior year value as well.
    Thank you for all your help!!what is prior year?

Maybe you are looking for

  • Damsel In Distress: Embedding Sound Clips in Fillable Forms

    I embedded sounds (WAV files) in my professional 7.0 pdf with both the sound tool and the button tool. I also customized these with my own icon (JPG and PNG images). PROBLEM: once I open my pdf as a fillable form to add comment boxes, all the sound c

  • Keynote for iOS

    Hello ;) I tried to download iWork (Keynote), but it is for 8,99... But i bought new iPhone in December 2013. What can I do for get it free? Sorry for my english :) THX for you answer

  • Imports Scenerio

    Dear Experts, I have an Imports Scenerio with two case 1)The material which is coming from abroad and came to port which we can take cenvat the material which is comming to factory 2) The material which is coming from abroad and came to port which we

  • Slideshow from selected images in folder - LR3 creates previews of all images

    I select a number of images in a folder in the Library module and go to the Slideshow module. When I run the slideshow LR3 generates previews of all of the images in the relevant folder - rather than merely those for the images I have selected. I'm r

  • Updating detail columns

    Guys, I am really really new to Apex (first day) I am playing around with the master detail form (which I will be using a lot). and I could not able to find a way to add validation / conditions to the columns in detail table. (I have setup my form so