How to include OSTC.rate in this query

How to include OSTC.rate in this query,Im using it for crystal report.
DECLARE @sVAT NVARCHAR(max) 
DECLARE @sCess NVARCHAR(max) 
DECLARE @sCST NVARCHAR(max) 
DECLARE @nDocentry  INT 
SET @sVAT='1'  SET @sCess='7' SET @sCST ='4'
SELECT DocEntry
  ,DocDate,VehicleNo,Driver,NumAtCard
  ,Building,Block,Street,City,District,State,Country
  ,Series,DocNum
  ,BTinNo,BCstNo,BCeRegNo,BPanNo,BCeRange,BCeComRate,BCeDivision,BEccNo
  ,Type
  ,CardName,[Delivery Addr]
  ,ECCNo,CERange,CERegNo,CEDivis,CEComRate
  ,PAN,CST,STN
  ,[Deliver At]
  ,LineNum
  ,Dscription,HSNumber,Quantity,Rate,LineTotal,Discount,Vat [VAT],Cess [Cess],Total,GTotal
  ,TotalExpns
  ,MfgName
  ,MFGBuilding,MFGBlock,MFGStreet,MFGDistrict,MFGCity
  ,MCERegNo,MCERange,MCEDivis,MCEComRate,MPAN,MCST,MSTN
  ,SupName
  ,SUPBuilding,SUPBlock,SUPStreet,SUPDistrict,SUPCity
  ,SCERegNo,SCERange,SCEDivis,SCEComRate,SPAN,SCST,SSTN
  , (select substring((select upper(name)+',' from OUBR where isnull(U_SeriesGrp,'')<>'' order by Code FOR XML PATH ('')),1,LEN((select upper(name)+',' from OUBR order by Code FOR XML PATH ('')))-1))[Branches]
FROM
SELECT
  /*OBTN.DistNumber*/
  INV1.DocEntry
  ,OINV.DocDate,OINV.U_VehicleNo VehicleNo,OINV.U_Driver Driver,OINV.NumAtCard
  ,CAST(OLCT.Building AS VARCHAR(255))Building,OLCT.Block,OLCT.Street,OLCT.City,OLCT.County+' - '+OLCT.ZipCode[District],OCST.Name State,OCRY.Name Country
  , NNM1.SeriesName [Series], OINV.DocNum
  ,OLCT.TinNo [BTinNo],OLCT.CstNo [BCstNo],OLCT.CeRegNo [BCeRegNo],OLCT.PanNo [BPanNo],OLCT.CeRange [BCeRange]
  ,OLCT.CeComRate [BCeComRate],OLCT.CeDivision [BCeDivision],OLCT.EccNo [BEccNo]
  ,OBTN.U_InvType Type
  ,OINV.CardName,OINV.Address2[Delivery Addr]
  ,CE_CRD7.ECCNo,CE_CRD7.CERegNo,CE_CRD7.CERange,CE_CRD7.CEDivis,CE_CRD7.CEComRate
  ,CRD7.TaxId0[PAN],CRD7.TaxId1[CST],CRD7.TaxId11 [STN]
  ,OINV.U_Address [Deliver At]
  ,INV1.LineNum,INV1.ItemCode
  ,INV1.Dscription,OITM.SWW [HSNumber]
  ,INV1.Quantity,INV1.PriceBefDi Price,INV1.LineTotal,INV1.Price Rate,(INV1.PriceBefDi-INV1.Price)*INV1.Quantity Discount
  ,INV4.Vat
  ,INV4.Cess
  ,INV1.LineTotal+INV1.VatSum Total 
  ,OINV.DocTotal GTotal
  ,OINV.TotalExpns
  ,OBTN.U_MfgName MfgName
  ,convert(nvarchar(250),MFG_CRD1.Building) MFGBuilding,MFG_CRD1.Block MFGBlock,MFG_CRD1.Street MFGStreet,MFG_CRD1.City MFGCity,MFG_CRD1.ZipCode[MFGDistrict]
  ,OBTN.U_MCERegNo MCERegNo,OBTN.U_MCERange MCERange,OBTN.U_MCEDivis MCEDivis,OBTN.U_MCEComRate MCEComRate
  ,OBTN.U_MPAN MPAN,OBTN.U_MCST MCST,OBTN.U_MSTN MSTN
  ,OBTN.U_SupName SupName
  ,convert(nvarchar(250),SUP_CRD1.Building) SUPBuilding,SUP_CRD1.Block SUPBlock,SUP_CRD1.Street SUPStreet,SUP_CRD1.City SUPCity,SUP_CRD1.ZipCode[SUPDistrict]
  ,OBTN.U_SCERegNo SCERegNo,OBTN.U_SCERange SCERange,OBTN.U_SCEDivis SCEDivis,OBTN.U_SCEComRate SCEComRate
  ,OBTN.U_SPAN SPAN,OBTN.U_SCST SCST,OBTN.U_SSTN SSTN
FROM
  OINV
  INNER JOIN INV1 ON OINV.DocEntry=INV1.DocEntry
  INNER JOIN OITM ON INV1.ItemCode=OITM.ItemCode
  INNER JOIN 
  select
  INV4.DocEntry,INV4.LineNum
  ,CASE WHEN INV4.staType IN (@sVAT,@sCST) THEN sum(INV4.TaxSum) ELSE 0 END Vat
  ,CASE WHEN INV4.staType=@sCess THEN sum(INV4.TaxSum) ELSE 0 END Cess
  from
  INV4
  where
  INV4.DocEntry={?DocKey@} and INV4.RelateType=1
  group by INV4.DocEntry,INV4.LineNum,INV4.staType
  )INV4 ON INV1.DocEntry=INV4.DocEntry AND INV1.LineNum=INV4.LineNum
  INNER JOIN OLCT ON INV1.LocCode=OLCT.Code
  INNER JOIN OCST ON OLCT.State=OCST.Code
  INNER JOIN OCRY ON OLCT.Country=OCRY.Code and OCST.Country=OCRY.Code
  INNER JOIN INV12 ON OINV.DocEntry=INV12.DocEntry
  INNER JOIN OITL ON INV1.BaseType=OITL.ApplyType AND INV1.BaseEntry=OITL.ApplyEntry AND INV1.BaseLine=OITL.ApplyLine
  INNER JOIN ITL1 ON OITL.LogEntry=ITL1.LogEntry
  INNER JOIN OBTN ON ITL1.MdAbsEntry=OBTN.AbsEntry and ITL1.SysNumber=OBTN.SysNumber and ITL1.ItemCode=OBTN.ItemCode
  LEFT JOIN OCRD MFG_OCRD ON MFG_OCRD.CardCode=OBTN.U_MfgCode
  LEFT JOIN CRD1 MFG_CRD1 ON MFG_OCRD.CardCode=MFG_CRD1.CardCode AND MFG_OCRD.BillToDef=MFG_CRD1.Address and MFG_CRD1.AdresType='B'
  LEFT JOIN OCRD SUP_OCRD ON SUP_OCRD.CardCode=OBTN.U_SupCode
  LEFT JOIN CRD1 SUP_CRD1 ON SUP_OCRD.CardCode=SUP_CRD1.CardCode AND SUP_OCRD.BillToDef=SUP_CRD1.Address and SUP_CRD1.AdresType='B'
  LEFT JOIN NNM1 ON OINV.Series=NNM1.Series
  LEFT JOIN CRD7 ON OINV.CardCode=CRD7.CardCode AND CRD7.Address='' AND CRD7.AddrType='S' --Tax Details
  LEFT JOIN CRD7 CE_CRD7 ON OINV.CardCode=CE_CRD7.CardCode AND OINV.ShipToCode=CE_CRD7.Address AND CE_CRD7.AddrType='S' -- Central Excise Details
  WHERE
  INV1.DocEntry={?DocKey@}
)INVOICE
GROUP BY
  DocEntry
  ,DocDate,VehicleNo,Driver,NumAtCard
  ,Building,Block,Street,City,District,State,Country
  ,Series,DocNum
  ,BTinNo,BCstNo,BCeRegNo,BPanNo,BCeRange,BCeComRate,BCeDivision,BEccNo
  ,Type
  ,CardName,[Delivery Addr]
  ,ECCNo,CERange,CERegNo,CEDivis,CEComRate
  ,PAN,CST,STN
  ,[Deliver At]
  ,LineNum
  ,Dscription,HSNumber,Quantity,Rate,LineTotal,Discount,Vat,Cess,Total,GTotal
  ,TotalExpns
  ,MfgName
  ,MFGBuilding,MFGBlock,MFGStreet,MFGDistrict,MFGCity
  ,MCERegNo,MCERange,MCEDivis,MCEComRate,MPAN,MCST,MSTN
  ,SupName
  ,SUPBuilding,SUPBlock,SUPStreet,SUPDistrict,SUPCity
  ,SCERegNo,SCERange,SCEDivis,SCEComRate,SPAN,SCST,SSTN

You're double posting ( how to change join condition in this query ) , stop doing that, since you'll only be distracting and diverting by doing so.
Take the time to read the SQL and PL/SQL FAQ @ https://forums.oracle.com/forums/ann.jspa?annID=1535, since you're not even mentioning a database version, while 9i {noformat} != {noformat} 10g {noformat} != {noformat}11g...
Have your DBA trace/tkprof the query, and so on, if you cannot do that yourself.
And then provide the feedback the volunteers, including Ace (Directors)' s need ( and you were very lucky, from that point of view, I think, from looking at both your posts ;) )

Similar Messages

  • Please help me how to improve the performance of this query further.

    Hi All,
    Please help me how to improve the performance of this query further.
    Thanks.

    Hi,
    this is not your first SQL tuning request in this community -- you really should learn how to obtain performance diagnostics.
    The information you posted is not nearly enough to even start troubleshooting the query -- you haven't specified elapsed time, I/O, or the actual number of rows the query returns.
    The only piece of information we have is saying that your query executes within a second. If we believe this, then your query doesn't need tuning. If we don't, then we throw it away
    and we're left with nothing.
    Start by reading this blog post: Kyle Hailey &amp;raquo; Power of DISPLAY_CURSOR
    and applying this knowledge to your case.
    Best regards,
      Nikolay

  • How to write SQL hints for this query?

    The query is like:
    select * from foo, t
    where foo.name in
    (select name from bar
    where id in (
    select id from car
    where date < sysdate
    and foo.a = t.b;
    I want the innermostsubquery 'select id from car ...' to be executed first, and the subquery 'select name from bar ...' to be execute second, and the outermost query 'select * from foo,t ...' to be executed the last. How can I write the Oracle sql hints to force the order?
    Thanks.

    user553560
    You might be able to create a large set of hints to force the access path you want - but unless you really know what you are doing with hints, you may find that your solution is very unstable (it might be luck rather than correctness that let's it work to start with).
    The difficulty in this query is the double layer of IN subqueries, so if you can rewrite the query, you might try manually unnesting as follows:
    select
         t1.*. t.*
    from
              select     
                   distinct t2.name
              from     t2
              where     t2.id in (
                        select     t3.id
                             from     t3
                        where     t3.dated < sysdate
         )     v,
         t1,
         t
    where
         t1.name = v.name
    and     t1.a = t.bDepending on your indexing and statistics, you may find that a simple /*+ unnest */ hint in the first subquery will be sufficient to do this for your. Again depending on the statistics you may find that you have to put extra hints into the above to make Oracle use the join method and indexes you think appropriate.
    N.B. The first step (as others have noted) is to check that your statistics are good before you start manipulating the code or using hints.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk

  • How to use outer join on this query?

    Hi all,
    Hope doing well,
    sir i am having one query which is here
    SELECT C.* ,
    P.Comp_Name Parent
    FROM Comp_Master C
    LEFT JOIN Comp_Master P
    ON C.Parent_ID = P.Comp_ID
    WHERE C.Comp_ID = 5;
    and here is my table Comp_Master data like this:
    Comp_ID Parent_ID Comp_Name
    5 1 abc123
    1 ROOT abc@123
    after running this query with all column value in parent column abc@123 value should come. but it's not happening.
    could u check this.
    if any query please let me know.
    Thanks

    p.s. when I run your query against your data....
    SQL> ed
    Wrote file afiedt.buf
      1  with comp_master as (select '5' comp_id, '1' parent_id, 'abc123' comp_name from dual union all
      2                       select '1' comp_id, 'ROOT' parent_id, 'abc@123' comp_name from dual
      3                      )
      4  --
      5  -- end of simulated table of test data
      6  --
      7  SELECT C.*
      8        ,P.Comp_Name Parent
      9  FROM Comp_Master C
    10       LEFT JOIN Comp_Master P ON C.Parent_ID = P.Comp_ID
    11* WHERE C.Comp_ID = 5
    SQL> /
    C PARE COMP_NA PARENT
    5 1    abc123  abc@123I get the output I expect from that query.
    So what are you expecting?
    I just ran the equivalent in SQL Server (I can't believe you got me to go and run that piece of rubbish... I haven't touched it in ages)...
    with comp_master as (select '5' comp_id, '1' parent_id, 'abc123' comp_name union all
                         select '1' comp_id, 'ROOT' parent_id, 'abc@123' comp_name
    SELECT C.*
          ,P.Comp_Name Parent
    FROM Comp_Master C
         LEFT JOIN Comp_Master P ON C.Parent_ID = P.Comp_ID
    WHERE C.Comp_ID = 5... and it gave me the same output.

  • How to Include 0GLACCEXT characteristic (FSV) into Query?

    I am trying to produce a Balance Sheet, I have the data coming in from GL and I have used Z cubes but I have copied all the data from Standard BI Content Cubes,  I have also created a Z Multi Provider based on the 0FIGL_VC1 virtual cube.
    In the query designer, I can see all the chars but the 0GLACCEXT (which is the FSV), I have uploaded the master data to this CHAR and I was going to include it in the rows section, but when I look through all the dimentions of the InfoProvider on the left hand pane ( of the BI7 Query designer) I can not find this CHAR, any clues or ideas as to what has happened?
    Please let me know if you have come accross it and how you resolved it... thanks

    0GLACCEXT does not exists in 0FIGL_C01, but exists in 0FIGL_VC1. There is a function module (someting like this /xxxxx/BCT_FIGL_DATA_GET_VC01) between these two, that has the logic to feed data for 0GLACCEXT from 0FIGL_C01.
    I have used Z cubes but I have copied all the data from Standard BI Content Cubes, I have also created a Z Multi Provider based on the 0FIGL_VC1 virtual cube.
    Looks like u have ...  Z cube --> 0FIGL_VC1 --> Z Multi Provider 
    In that case, u have to copy that function module between Z cube & 0FIGL_VC1, so that 0GLACCEXT (0FIGL_VC1) gets filled.
    To see that function module..
    Double click on 0FIGL_VC1 --> goto change mode --> click on Information (blue ' i ' ) icon --> click on "Type/Namespace" tab --> click "details" tab
    Here u can see function module ( someting like this /xxxxx/BCT_FIGL_DATA_GET_VC01).
    If u check standard queries... all the queries related to balance sheet, defined on virtual provider (0FIGL_VC1, 0FIGL_VC2 & 0FIGL_VC10), but not on the cubes. The reason behind this is, only the virtual provider consists of 0GLACCEXT

  • How to build where clause in this query

    Hi all,
    Version Details
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE     11.2.0.2.0     Production
    TNS for Solaris: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    Status_cid  filter in the following query should be 3,86,25 for org_unit_sid 3001 and for other organizations it should be 5,86 .
    Please let me know how this can be done .
    SELECT *
      FROM table_name pr
    WHERE pr.status_cid IN              /*pr.status_cid is number (2) data type * /
              ((CASE
                   WHEN pr.org_unit_sid = 3001
                      THEN (SELECT '5,86,25'   -- this is not working
                              FROM DUAL)
                   ELSE (SELECT '5,25'
                           FROM DUAL)
                END
    I know this can be done using union  as follows ..
    SELECT *
      FROM ((SELECT *
               FROM temp pr
              WHERE pr.org_uni_sid = 3001 AND pr.status_cid IN (5, 86, 25))
            UNION
            (SELECT *
               FROM temp pr
              WHERE pr.org_uni_sid <> 3001 AND pr.status_cid IN (5, 86)))
    Any help in this regard  is appreciated .............Thanks,
    P Prakash

    SELECT *
    FROM   table_name pr
    WHERE ( (pr.status_cid IN (5,86) OR ( pr.org_unit_sid = 3001 AND pr.status_cid IN (25))
    {code}
    PS: Kindly mark the answers to your post as helpfull/correct if you are satisfied
    Edited by: Himanshu Binjola on Apr 23, 2012 9:34 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Utl_raw.bit_and - how can I improve performance of this query?

    Hi all
    Hugely grateful for any light anyone can shed.
    I need to do bit AND operations on 128 bit numbers and I'm stuck in Oracle 10g.
    10g provides a very nice bitand() function that can be applied to numbers but it only works up to 64 bit numbers (actually only 62 I think because it needs a couple of bits)
    So I've been looking at using the utl_raw.bit_and function. It works very well, except that I'm encountering a massive performance hit, which hopefully is in the way I'm using it, rather than intrinsic to the speed at which utl_raw.bit_and itself performs..
    With numbers, I do a query like this:
    select count(1) from offer_a where bitand(bit_column, 51432) = 51432
    With utl_raw.bit_and (and 16-byte RAW column), I am passing in a hex value (may not be the best thing? Would passing in binary be better?) and doing my query like this:
    select count(1) from offer_a where utl_raw.bit_and(bit_column,hextoraw('00000000000000000020008000002ca1')) = hextoraw('00000000000000000020008000002ca1');
    One million rows using bitand takes about a second, using utl_raw.bit_and like this takes 25 seconds or so!!! Hopefully it's something in the way I'm calling it, and there's a faster way?
    Thank you!
    Jake

    Hmm.. Actually it may not be that simple.
    I had created an index on the number column that oracle seems to consistently use if I do a query like:
    select count(1) from scott.offer_b where
    current_price >= 0 and
    bitand(current_price, 9008574719100165) = 9008574719100165
    (without the >= oracle seems to do a full table scan. The reason I created the index is that there's other columns in the data table, making larger blocks. I figured that an index, even though most of needs to be scanned, would be faster because I can cram many more rows into each block..?).
    But if I drop the index on the number column, it takes about 12 secs/1m rows, in other words about half the time of the utl_raw.bit_and().
    So it's possible that bitand on 64 bits takes about half the time of utl_raw.bit_and on 128 bits, which is very reasonable..
    So maybe the real problem I have is why oracle is not using the equivalent index that I placed on the RAW column when I do:
    select count(1) from scott.offer_b where
    hex_bit_sig >= '00000000000000000020008000002ca1' and
    utl_raw.bit_and(hex_bit_sig,'00000000000000000020008000002ca1') = '00000000000000000020008000002ca1';
    (By the way I realized that I don't need to use the hextoraw - seems like just putting a hex number in '' is the right way to specify a raw anyway?)
    So yes, I think that's the real problem - how can I get oracle to use the index I created on the RAW value

  • How to use GROUP BY in this Query

    The below query has TRUNC funtion and I don't want the NMR field to put in group by, but it should be in select.
    Please help
    SELECT H.SAM_ATTUID AS ATTUID1,
    B.AGENT_ID,
    TRUNC (NVL (FORC_ANNREV_PAID, CALC_ANNREV_PAID) / 12, 2) AS NMR,
    PRODUCT_GROUP
    FROM CNT380_TRAN_DATA A,
    CNT350_INWARD_DATA B,
    CNT330_CODE_VALUE C,
    CNT460_COMM_DATA D,
    CNT100_PROD_CUST E,
    CNT120_AGENT F,
    CNT127_AGENT_CAM G,
    CNT470_SAM H,
    CNT481_MSA_SAM K
    WHERE A.INWD_REF_NBR = B.INWD_REF_NBR
    AND A.INWD_REF_NBR = A.REF_NBR
    AND A.INWD_REF_NBR = D.INWD_REF_NBR
    AND A.CYCLE_DATE &gt;= '01-SEP-08'
    AND A.CYCLE_DATE &lt;= '30-SEP-08'
    AND B.SUBSID_CD = 'EAST'
    AND INWD_AGENT_CHAN = 'EALI'
    AND (NVL(FORC_ANNREV_PAID,CALC_ANNREV_PAID) &lt;&gt; 0
    OR NVL(FORC_ANNREV_RECOUP,CALC_ANNREV_RECOUP) 0)
    AND (B.PROD_CLASS_CD 'MSGWK' OR B.PROD_CLASS_CD IS NULL)
    AND RTRIM(B.ALTERNATE_PROD_CD) = RTRIM(C.CD_VALUE (+) )
    AND RTRIM(A.SPECIAL_PROCESS_IND) IN
    'ADD'
    ,'NEW'
    ,'WB'
    AND A.ACTIVITY_IND = 'I'
    AND B.AGENT_ID = G.AGENT_ID (+)
    AND B.SUBSID_CD = G.SUBSID_CD (+)
    AND A.SO_CMPL_DATE &gt;= G.START_EFF_DATE
    AND (A.SO_CMPL_DATE &lt;= G.END_EFF_DATE OR G.END_EFF_DATE IS NULL)
    AND (H.SAM_ATTUID &lt;&gt; 'DUMMY' AND H.SAM_ATTUID IS NOT NULL)
    AND H.SAM_CD=K.SAM_CD
    AND H.SUBSID_CD=K.SUBSID_CD
    group by
    b.AGENT_ID,
    PRODUCT_GROUP,
    SAM_ATTUID

    You have two choice
    1. Use an aggregate function like MIN, MAX etc on FORC_ANNREV_PAID, CALC_ANNREV_PAID
    2. Include FORC_ANNREV_PAID, CALC_ANNREV_PAID in the group by.
    Thanks,
    Karthick.

  • How do I use count for this query?

    How do I display all the addresses in a table that have more than one (or >1) account number? I wasn't sure how or if I should use count along with group by and having to get the expected results.

    select address from tablename
    group by address having count(1) > 1;

  • How to include variable on block's query

    I have a block where I fetch data using Query with sub-querry on Query data source name. The problem is that I need to put a variable in a sub-query, but it returned error: ORA-01008 not all variables bound. I'm retrieving multiple records here.
    SELECT DISTINCT --fields
    FROM table1 a, table2 b, table3 c, table4 d
    WHERE a.line_cd = b.line_cd
    AND a.line_cd = 21
    --other conditions
    AND a.clm_seq_no = 7100003
    AND d.eff_dt = (SELECT MAX(eff_dt)
              FROM table4
              WHERE 1=1
              AND srvc_code = a.srvc_code
              AND line_cd = a.line_cd
              AND sched_no = a.sched_no
              AND cover_code = a.cover_code
              AND eff_dt <= :global.variable --problem
    )

    Thanks for your replies.
    Query Data source typy = Table, I also tried using package that serves as handler of global variable (variables.eff_dt) but it gives me error (cannot perform query).
    ( SELECT * FROM (SELECT DISTINCT a.claimant_seq, a.expense_title title,
    NVL(c.max_chrg, 0) max_chrg, NVL(c.min_chrg, 0) min_chrg, DECODE(tran_type, 2,
    a.amount * -1, a.amount) amnt, a.line_cd, a.subline_cd, a.iss_cd, a.clm_yy,
    a.clm_seq_no, a.item_no, a.peril_cd, a.sched_no, a.cover_code, a.srvc_code,
    a.srvc_dtl_code, NVL(a.days, 0) no_days, c.no_days days, NVL(d.min_chrg, 0) MIN,
    NVL(d.max_chrg, 0) MAX, a.dtls_seq, a.limit_amt, a.ctpl_amt, a.excess_amt
    FROM VTPLBI_DTLS a, POL_COVERAGE b, POL_SRVC_DTLS c, pol_services d
    WHERE a.line_cd = b.line_cd
    AND a.sched_no = b.sched_no
    AND a.cover_code = b.cover_code
    AND b.line_cd = d.line_cd
    AND b.sched_no = d.sched_no
    AND b.cover_code = d.cover_code
    AND a.srvc_code = d.srvc_code
    AND a.srvc_code = c.srvc_code(+)
    AND a.line_cd = c.line_cd(+)
    AND a.sched_no = c.sched_no(+)
    AND a.cover_code = c.cover_code(+)
    AND a.srvc_dtl_code = c.srvc_dtl_code(+)
    AND d.eff_dt = (SELECT MAX(eff_dt) --wency05082007
              FROM POL_SERVICES
              WHERE 1=1
              AND srvc_code = a.srvc_code
              AND line_cd = a.line_cd
              AND sched_no = a.sched_no
              AND cover_code = a.cover_code
              AND eff_dt <= variables.v_eff_dt --here is the problem
    UNION SELECT DISTINCT a.claimant_seq, a.expense_title, 0, 0, DECODE(tran_type,
    2, a.amount * -1, a.amount) amnt, a.line_cd, a.subline_cd, a.iss_cd, a.clm_yy,
    a.clm_seq_no, a.item_no, a.peril_cd, a.sched_no, a.cover_code, a.srvc_code,
    a.srvc_dtl_code, NVL(a.days, 0) no_days, 0, 0, 0, a.dtls_seq, a.limit_amt,
    a.ctpl_amt, a.excess_amt
    FROM VTPLBI_DTLS a
    WHERE (a.sched_no = 2 or a.sched_no is null) )
    ORDER BY dtls_seq ) comp_dtl
    Message was edited by:
    Wency

  • How to performance tune this query

    I need some inputs on how to do performance tuning on this query to improve performance.
    It takes around 45 secs to run. Is it possible to make any improvements in this by putting hints or writing in another way?
    select count(*)
    as nCount from A ,
    B ,
    C
    WHERE A.COL1 = B.COL1 AND
    A.COl2 <> 'COM' AND
    B.COL2 = C.COL1 AND
    B.COl3 IS NULL AND
    B.COL4 = 'TEST'
    This is the query plan:
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE 1 51
    SORT AGGREGATE 1 37
    HASH JOIN 48 K 1 M 51
    TABLE ACCESS FULL A 68 K 998 K 32
    NESTED LOOPS 98 K 2 M 5
    TABLE ACCESS BY INDEX ROWID B 142 K 2 M 4
    INDEX SKIP SCAN XIF37B 142 K 6
    INDEX UNIQUE SCAN XPKC 1 5

    Mcka
    As well as EXPLAIN PLAN, let us know what proportion of rows are visited by this query. It may be that it is not using a full table scan when it should (or vice versa).
    And of course we'd need to know what indexes are available, and how selective they are for the predicated you have in this query ...
    Regards Nigel

  • Performance issue with this query.

    Hi Experts,
    This query is fetching 500 records.
    SELECT
    RECIPIENT_ID ,FAX_STATUS
    FROM
    FAX_STAGE WHERE LOWER(FAX_STATUS) like 'moved to%'
    Execution Plan
    | Id  | Operation                   | Name                | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT            |                     |   159K|    10M|  2170   (1)|
    |   1 |  TABLE ACCESS BY INDEX ROWID| FAX_STAGE           |   159K|    10M|  2170   (1)|
    |   2 |   INDEX RANGE SCAN          | INDX_FAX_STATUS_RAM | 28786 |       |   123   (0)|
    Note
       - 'PLAN_TABLE' is old version
    Statistics
              1  recursive calls
              0  db block gets
             21  consistent gets
              0  physical reads
              0  redo size
            937  bytes sent via SQL*Net to client
            375  bytes received via SQL*Net from client
              3  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
             19  rows processed
    Total number of records in the table.
    SELECT COUNT(*) FROM FAX_STAGE--3679418
    Distinct reccords are low for this column.
    SELECT DISTINCT FAX_STATUS FROM FAX_STAGE;
    Completed
    BROKEN
    Broken - New
    moved to - America
    MOVED to - Australia
    Moved to Canada and australia
    Functional based indexe on FAX_STAGE(LOWER(FAX_STATUS))
    stats are upto date.
    Still the cost is high
    How to improve the performance of this query.
    Please help me.
    Thanks in advance.

    With no heavy activity on your fax_stage table a bitmap index might do better - see  CREATE INDEX
    I would try FTS (Full Table Scan) first as 6 vs. 3679418 is low cardinality for sure so using an index is not very helpful in this case (maybe too much Exadata oriented)
    There's a lot of web pages where you can read: full table scans are not always evil and indexes are not always good or vice versa Ask Tom &amp;quot;How to avoid the full table scan&amp;quot;
    Regards
    Etbin

  • How I can change this query, so I can display the name and scores in one r

    How I can change this query, so I can add the ID from the table SPRIDEN
    as of now is giving me what I want:
    1,543     A05     24     A01     24     BAC     24     BAE     24     A02     20     BAM     20in one line but I would like to add the id and name that are stored in the table SPRIDEN
    SELECT sortest_pidm,
           max(decode(rn,1,sortest_tesc_code)) tesc_code1,
           max(decode(rn,1,score)) score1,
           max(decode(rn,2,sortest_tesc_code)) tesc_code2,
           max(decode(rn,2,score)) score2,
           max(decode(rn,3,sortest_tesc_code)) tesc_code3,
           max(decode(rn,3,score))  score3,
           max(decode(rn,4,sortest_tesc_code)) tesc_code4,
           max(decode(rn,4,score))  score4,
           max(decode(rn,5,sortest_tesc_code)) tesc_code5,
           max(decode(rn,5,score))  score5,
           max(decode(rn,6,sortest_tesc_code)) tesc_code6,
           max(decode(rn,6,score))  score6        
      FROM (select sortest_pidm,
                   sortest_tesc_code,
                   score,
                  row_number() over (partition by sortest_pidm order by score desc) rn
              FROM (select sortest_pidm,
                           sortest_tesc_code,
                           max(sortest_test_score) score
                      from sortest,SPRIDEN
                      where
                      SPRIDEN_pidm =SORTEST_PIDM
                    AND   sortest_tesc_code in ('A01','BAE','A02','BAM','A05','BAC')
                     and  sortest_pidm is not null 
                    GROUP BY sortest_pidm, sortest_tesc_code))
                    GROUP BY sortest_pidm;
                   

    Hi,
    That depends on whether spriden_pidm is unique, and on what you want for results.
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevamnt columns only) for all tables, and the results you want from that data.
    If you can illustrate your problem using commonly available tables (such as those in the scott or hr schemas) then you don't have to post any sample data; just post the results you want.
    Either way, explain how you get those results from that data.
    Always say which version of Oracle you're using.
    It looks like you're doing something similiar to the following.
    Using the emp and dept tables in the scott schema, produce one row of output per department showing the highest salary in each job, for a given set of jobs:
    DEPTNO DNAME          LOC           JOB_1   SAL_1 JOB_2   SAL_2 JOB_3   SAL_3
        20 RESEARCH       DALLAS        ANALYST  3000 MANAGER  2975 CLERK    1100
        10 ACCOUNTING     NEW YORK      MANAGER  2450 CLERK    1300
        30 SALES          CHICAGO       MANAGER  2850 CLERK     950On each row, the jobs are listed in order by the highest salary.
    This seems to be analagous to what you're doing. The roles played by sortest_pidm, sortest_tesc_code and sortest_test_score in your sortest table are played by deptno, job and sal in the emp table. The roles played by spriden_pidm, id and name in your spriden table are played by deptno, dname and loc in the dept table.
    It sounds like you already have something like the query below, that produces the correct output, except that it does not include the dname and loc columns from the dept table.
    SELECT    deptno
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
               SELECT    deptno
               ,          job
               ,          max_sal
               ,          ROW_NUMBER () OVER ( PARTITION BY  deptno
                                              ORDER BY          max_sal     DESC
                                )         AS rn
               FROM     (
                             SELECT    e.deptno
                       ,           e.job
                       ,           MAX (e.sal)     AS max_sal
                       FROM      scott.emp        e
                       ,           scott.dept   d
                       WHERE     e.deptno        = d.deptno
                       AND           e.job        IN ('ANALYST', 'CLERK', 'MANAGER')
                       GROUP BY  e.deptno
                       ,           e.job
    GROUP BY  deptno
    ;Since dept.deptno is unique, there will only be one dname and one loc for each deptno, so we can change the query by replacing "deptno" with "deptno, dname, loc" throughout the query (except in the join condition, of course):
    SELECT    deptno, dname, loc                    -- Changed
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
               SELECT    deptno, dname, loc          -- Changed
               ,          job
               ,          max_sal
               ,          ROW_NUMBER () OVER ( PARTITION BY  deptno      -- , dname, loc     -- Changed
                                              ORDER BY          max_sal      DESC
                                )         AS rn
               FROM     (
                             SELECT    e.deptno, d.dname, d.loc                    -- Changed
                       ,           e.job
                       ,           MAX (e.sal)     AS max_sal
                       FROM      scott.emp        e
                       ,           scott.dept   d
                       WHERE     e.deptno        = d.deptno
                       AND           e.job        IN ('ANALYST', 'CLERK', 'MANAGER')
                       GROUP BY  e.deptno, d.dname, d.loc                    -- Changed
                       ,           e.job
    GROUP BY  deptno, dname, loc                    -- Changed
    ;Actually, you can keep using just deptno in the analytic PARTITION BY clause. It might be a little more efficient to just use deptno, like I did above, but it won't change the results if you use all 3, if there is only 1 danme and 1 loc per deptno.
    By the way, you don't need so many sub-queries. You're using the inner sub-query to compute the MAX, and the outer sub-query to compute rn. Analytic functions are computed after aggregate fucntions, so you can do both in the same sub-query like this:
    SELECT    deptno, dname, loc
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
                   SELECT    e.deptno, d.dname, d.loc
              ,       e.job
              ,       MAX (e.sal)     AS max_sal
              ,       ROW_NUMBER () OVER ( PARTITION BY  e.deptno
                                           ORDER BY       MAX (sal)     DESC
                                          )       AS rn
              FROM      scott.emp    e
              ,       scott.dept   d
              WHERE     e.deptno        = d.deptno
              AND       e.job                IN ('ANALYST', 'CLERK', 'MANAGER')
                  GROUP BY  e.deptno, d.dname, d.loc
              ,       e.job
    GROUP BY  deptno, dname, loc
    ;This will work in Oracle 8.1 and up. In Oracle 11, however, it's better to use the SELECT ... PIVOT feature.

  • How to include 0STOCK_VAL in a Query based on APO DataSource?

    Hi All,
    I have a requirement to include *0STOCK_VAL" from Inventory to the APO InfoCube. But the problem with this is, this particular KeyFigure is not present in the APO hence it cannot be included in the APO DataSource i.e. we cannot get this from the Source System.
    I checked the Production system, 0STOCK_VAL InfoObject is avaiable in one of the InfoCube but it is not present in any DSO's. Since it is not present in any of the DSO's we cannot write a Routine to read it from any of the table.
    I even thought of including the InfoCube where 0STOCK_VAL is present into a MultiProvider along with the APO InfoCube. I can define the joining condition based on Plant and Material. But if I drill down any other characteristics which are not common in both the  InfoCube then we will have a blank line in the Query which is not recommended.
    But this KeyFigure is very much needed in the Query.
    My question is how to include this in the APO InfoCube or How to get this in the Query with values??
    Can anybody please help me on this.
    Thanks in advance.
    Prasapbi

    hi Matt,
      In your example like a transaction was paid for with a payment type of PTAM, then you need all the transaction details. I suppose that all the required transaction details along with payment type PTAM will be loaded into an infoprovider and you run a report on top of this infoprovider. Then for that report you need to have a selection screen variable for Payment Type and if the user enters the payment type PTAM, then he can get all the other transaction details from the infoprovider.
    Let me know if i don't understand the requirement correctly.
    Hope it helps....

  • How do I get this query into Discoverer Plus

    Hi all,
    I have the following query:
    SELECT h.hrs, NVL(Quantity, 0) Quantity
    FROM (SELECT TRIM(to_char(LEVEL - 1, '00')) hrs
    FROM dual
    CONNECT BY LEVEL < 25) h
    LEFT JOIN (SELECT TO_CHAR(event_date, 'HH24') AS during_hour,
    COUNT(*) Quantity
    FROM user_activity u
    WHERE event_date BETWEEN
    to_date('15-JUN-2010 14:00:00', 'DD-MON-YYYY HH24:MI:SS') AND
    to_date('16-JUN-2010 13:59:59', 'DD-MON-YYYY HH24:MI:SS')
    AND event = 'user.login'
    GROUP BY TO_CHAR(event_date, 'HH24')) t
    ON (h.hrs = t.during_hour)
    ORDER BY h.hrs;
    Which produces the number of actions performed (from an event table, user_activity) grouped by the hour of the day they occurred (including displaying hours that have zero records - this bit is important!). I want to be able to put this into Discoverer plus as a worksheet, but I'm having trouble trying to figure out how.
    I was able to create a custom folder in Administrator for the select from DUAL, but I cannot link it to the user_activity table because there's no relationship between to two tables to create a join.
    The user_activity table is:
    USER_ID - VARCHAR2(8 CHAR)
    EVENT_DATE - DATE
    EVENT - VARCHAR2(100 CHAR)
    The custom folder is this part of the SQL:
    SELECT TRIM(to_char(LEVEL - 1, '00')) hrs FROM dual CONNECT BY LEVEL < 25
    Any suggestions would be greatly appreciated.
    Thanks.
    Edited by: Cyntech on Aug 12, 2010 10:41 AM

    KK wrote:
    hi,
    In the custom folder we can join tables,but the thing is you said ther is no join between them.
    I would suggest you to built this query into a view and use this view in the DUAL table by writing inline query or subquery what ever way.
    This is the only possibility i can think off.
    Hope it helps you.
    By,
    KKHi,
    Thanks for the reply, though I'm not sure that I understand what you are suggesting.
    Which query would you turn into a view? If you are referring to the select from dual, then how would the view be any different from the custom folder? You still would not be able to join it to user_activity as there are no common columns.
    Edited by: Cyntech on Aug 12, 2010 2:49 PM

Maybe you are looking for