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 >= '01-SEP-08'
AND A.CYCLE_DATE <= '30-SEP-08'
AND B.SUBSID_CD = 'EAST'
AND INWD_AGENT_CHAN = 'EALI'
AND (NVL(FORC_ANNREV_PAID,CALC_ANNREV_PAID) <> 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 >= G.START_EFF_DATE
AND (A.SO_CMPL_DATE <= G.END_EFF_DATE OR G.END_EFF_DATE IS NULL)
AND (H.SAM_ATTUID <> '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.

Similar Messages

  • 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 can I use lead/lag in this query

    I have written this query which gives me the comparative data based on this week and next week. How can I use Lead/Lag in this query.
       WITH CURRENT_WEEK
              AS (  SELECT   QPAQ.YEAR YEAR,
                             QPAQ.SEASON SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+') ACC_SERIES,
                             TO_NUMBER (QPAQ.WEEK) WEEK,
                             MAX (QPAQ.FAILURES) FAILURES
                      FROM   QAR_PLAN_ACC_QTY QPAQ, QAR_PLAN_THRESHOLD_LST QPTL
                     WHERE       QPTL.CATEGORY_ID = 7
                             AND QPAQ.YEAR = QPTL.YEAR
                             AND QPAQ.SEASON = QPTL.SEASON
                             AND QPAQ.SERIES_NAME = QPTL.MODEL_SERIES
                  GROUP BY   QPAQ.YEAR,
                             QPAQ.SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'),
                             TO_NUMBER (QPAQ.WEEK)
                  ORDER BY   REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+')),
           LAST_WEEK
              AS (  SELECT   QPAQ.YEAR YEAR,
                             QPAQ.SEASON SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+') ACC_SERIES,
                             TO_NUMBER (QPAQ.WEEK + 1) WEEK,
                             MAX (QPAQ.FAILURES) FAILURES
                      FROM   QAR_PLAN_ACC_QTY QPAQ, QAR_PLAN_THRESHOLD_LST QPTL
                     WHERE       QPTL.CATEGORY_ID = 7
                             AND QPAQ.YEAR = QPTL.YEAR
                             AND QPAQ.SEASON = QPTL.SEASON
                             AND QPAQ.SERIES_NAME = QPTL.MODEL_SERIES
                  GROUP BY   QPAQ.YEAR,
                             QPAQ.SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'),
                             TO_NUMBER (QPAQ.WEEK)
                  ORDER BY   REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'))
         SELECT   CURRENT_WEEK.YEAR,
                  CURRENT_WEEK.SEASON,
                  CURRENT_WEEK.ACC_SERIES,
                  CURRENT_WEEK.WEEK,
                  CURRENT_WEEK.FAILURES,
                  (CURRENT_WEEK.FAILURES - LAST_WEEK.FAILURES) FAILURES_COMPARE
           FROM   LAST_WEEK, CURRENT_WEEK
          WHERE   CURRENT_WEEK.WEEK = LAST_WEEK.WEEK(+)
       ORDER BY   CURRENT_WEEK.WEEK;Output is like this.
                    YEAR         SEASON     MODEL                     WEEK        FAILURES    Failures_COMPARE
    1     2011     SUMMER     VGP-BMS15     49     10     
    2     2011     SUMMER     VGP-BMS15     50     28       18
    3     2011     SUMMER     VGP-BMS15     51     30       2
    4     2011     SUMMER     VGP-BMS15     52     40       10Edited by: BluShadow on 06-Jan-2012 13:26
    added {noformat}{noformat} tags. Please read {message:id=9360002} to learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You would jettison the entire LAST_WEEK subquery. Then replace your failure calculation with
        current_week.failure - lag(current_week.failure) over (order by current_week.year, current_week.week) as failures_compareI suppose you might want to think about renaming the sub-query as well ....
    Cheers, APC
    Edited by: APC on Jan 6, 2012 1:41 PM

  • 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 ;) )

  • How to use "group" in iTunes?

    Hi...
    Need advice:
    Any ideas for how to use "Groups" under album "info" (cmd i)  
    (my iTunes is in Swedish, I am not sure what the English names are)
    This function has such a central position in "song info" but I cant understand how to use it...
    Best regards

    When I look in Edit > Preferences > General tab I find that the Libray name is still one of the old ones
    Then you are not opening a new library.
    If I rename to the library name it should be it still puts files in the wrong place.
    You should not rename the libraries.

  • How to use bind variables in this procedure

    Hi Experts,
    How to use bind variables in this procedure for static queries.
    PROCEDURE DELETE_MER_PROC (M_id IN NUMBER)
    IS
    BEGIN
    V_date DATE;
    SELECT PD_DATE INTO v_date FROM PD_MAINTAIN;
        DELETE FROM MER_CLEAR
        WHERE MER_DT < v_date
        AND ID = M_ID;
    COMMIT;
    END;   
    How to use  v_date and m_id as bind variables in this procedure to avoid hard parsing.
    Please help me.
    Thanks.

    976208 wrote:
    How to use  v_date and m_id as bind variables in this procedure to avoid hard parsing.
    You cannot avoid hard parsing - as the 1st time a SQL statement (like the SELECT or DELETE statements in your code) is encountered, it does not reside in the server's Shared Pool, and needs to be added into the pool via a hard parse.
    Bind variables does not prevent hard parsing. Hard parsing happens when the SQL statement (with or without bind variables) is a brand new statement encountered by the server.
    Bind variables enables the same SQL cursor to be reused, by simply changing the bind variable value.
    Not using bind variables means that each SQL statement is unique and not shareable - as the value is hardcoded into the statement and cannot be changed via a bind value. This typically means LOTS of different SQL statements (where the only difference is the changed value in the statement) are created - with each statement being a new statement not seen before in the Shared Pool and needing to be hard parsed.
    One does not design one's code not to be hard parsed. There ALWAYS will be a hard parse in order to get a SQL statement into the Shared Pool. One designs one's code to REUSE cursors in the Shared Pool.

  • How to use GROUP BY  in ODI

    how to use GROUP BY in ODI tool

    Hi ,
    you can combine the insert stamt with the select ....so that in the target u will get a single line .....
    SQL&gt; select * from prop_details;
    PROPERTY RELAVANTD NOTICES
    10100 25-JAN-09 30
    10100 03-JAN-09 30
    10100 02-DEC-08 20
    10100 01-DEC-08 10
    10100 31-DEC-08 20
    10101 10-JAN-09 10
    10101 20-JAN-07 15
    10101 30-DEC-08 45
    10101 20-FEB-08 35
    10101 31-JAN-09 25
    10 rows selected.
    SQL&gt; select PROPERTY,max(RELAVANTDATE),SUM(NOTICES) from PROP_DETAILS GROUP BY P
    ROPERTY;
    PROPERTY MAX(RELAV SUM(NOTICES)
    10101 31-JAN-09 130
    10100 25-JAN-09 110
    SQL&gt;

  • How to use shift register in this structure?

    Dear All,
    In order to use less variety of graph, I want to use shift register to manage and send data to graph.
    But there is not only event structure in my vi, for some reason(because I want to use only one button to control running and stop, and this must do through variety of button, I can't put this loop into the event structure) I must use other while loops, I don't know how to use shift register in this structure.
    Please tell me anything helpful.
    Thank you!
    Attachments:
    shift register.vi ‏26 KB

    hi there
    there are a lot of solutions. my favorite one is the usage of a so called "FGV" (functional global variable). this allows you to strore, manipulate and transport data through your app with a minimum of wires. see attachment.. (other users may have other favorite solutions...)
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"
    Attachments:
    Shift Register 7.1.zip ‏20 KB

  • 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 use parrallel cursor in this code

    hi can anyone expalin me how to use parallel cursor for this code ... 
    loop at itabkpf.
          read table ibsegpar_fu with key
                     belnr = itabkpf-belnr
                     gjahr = itabkpf-gjahr
                     bschl = '25' .
    Start insert by Pradeep 20082008
          sort: itabkpf by belnr,
                itabsegpar by belnr.
    End insert by Pradeep 20082008
          if sy-subrc = 0. "Deleted by pradeep 20082008
            select bukrs belnr gjahr bschl koart lifnr wrbtr
                   wskto pswbt zfbdt augbl augdt sgtxt rebzg rebzj
                   into corresponding
                   fields of table ibsegpar_fu_1 from bseg
                   where bukrs = itabkpf-bukrs and
                   belnr = itabkpf-belnr and
                   gjahr = itabkpf-gjahr and
                   augbl <> itabkpf-belnr and
                   rebzg <> space and
                   bschl = '25'.
            loop at ibsegpar_fu_1.
    Start insert by Pradeep 20082008
              sort ibsegpar_fu_1 by belnr.
    End insert by Pradeep 20082008
              move-corresponding ibsegpar_fu_1 to itabseg.
              move ibsegpar_fu_1-belnr to itabseg-augbl.
              move ibsegpar_fu_1-rebzg to itabseg-belnr.
              move ibsegpar_fu_1-rebzj to itabseg-gjahr.
    *********to include code to pick the description for partical payment
              select single * from bseg where
                  bukrs = ibsegpar_fu_1-bukrs and
                  belnr = ibsegpar_fu_1-belnr and
                  gjahr = ibsegpar_fu_1-gjahr and
                  augbl <> ibsegpar_fu_1-belnr and
                  rebzg = space and
                  bschl <> '25'.
              move bseg-sgtxt to itabseg-sgtxt.
              clear bseg.
    *********end of code
              itabseg-wrbtr = itabseg-wrbtr * -1.
              itabseg-pswbt = itabseg-pswbt * -1.
              select single budat into lsdat from
                   bkpf where bukrs = ibsegpar_fu_1-bukrs and
                   belnr = ibsegpar_fu_1-rebzg and
                   gjahr = ibsegpar_fu_1-rebzj.
              if sy-subrc = 0.
                move lsdat to itabseg-zfbdt.
              endif.
              append itabseg.
            endloop.
          endif. "Deleted by Pradeep 20082008
        endloop.
        loop at ibsegpar_fu.
          sort ibsegpar_fu by belnr. " insert by pradeep
          move-corresponding ibsegpar_fu to itabseg.
          select bukrs belnr gjahr bschl koart lifnr wrbtr
                 rebzg rebzj sgtxt into corresponding
                 fields of table ibsegpar_fu_1 from bseg
                 where  bukrs = ibsegpar_fu-bukrs and
                 gjahr = ibsegpar_fu-gjahr and
                 augbl = ibsegpar_fu-belnr and  " Pradeep 20082008 Delete
                augbl <> ibsegpar_fu-belnr and " Pradeep 20082008 Insert
                 rebzg = space and
                 bschl = '25'.
          if sy-subrc = 0.
            loop at ibsegpar_fu_1.
              move ibsegpar_fu_1-rebzg to itabseg-rebzg.
              move ibsegpar_fu_1-rebzj to itabseg-rebzj.
            endloop.
            move ibsegpar_fu-belnr to itabseg-augbl.
            move itabseg-rebzg to itabseg-belnr.
            move itabseg-rebzj to itabseg-gjahr.
            itabseg-wrbtr = itabseg-wrbtr * -1.
            itabseg-pswbt = itabseg-pswbt * -1.
            select single budat into lsdat from
                 bkpf where bukrs = ibsegpar_fu-bukrs and
                 belnr = itabseg-rebzj and
                 gjahr = itabseg-rebzj.
            if sy-subrc = 0.
              move lsdat to itabseg-zfbdt.
            endif.
            append itabseg.
            read table itabseg with key
                 belnr = itabseg-rebzg
                 gjahr = itabseg-rebzj
                 bschl = '31' .
            if sy-subrc = 0.
             delete itabseg index sy-tabix. "Deleted by Pradeep 20082108
            endif.
          endif.
        endloop.
    Start insert by Pradeep 20082008
         loop at itabseg.
          if itabseg-belnr = itabseg-augbl.
            delete itabseg.
          elseif itabseg-belnr = ' '.
            delete itabseg.
          endif.
        endloop.
    End insert by Pradeep 20082008

    hi can anyone expalin me how to use parallel cursor for this code ... 
    loop at itabkpf.
          read table ibsegpar_fu with key
                     belnr = itabkpf-belnr
                     gjahr = itabkpf-gjahr
                     bschl = '25' .
    Start insert by Pradeep 20082008
          sort: itabkpf by belnr,
                itabsegpar by belnr.
    End insert by Pradeep 20082008
          if sy-subrc = 0. "Deleted by pradeep 20082008
            select bukrs belnr gjahr bschl koart lifnr wrbtr
                   wskto pswbt zfbdt augbl augdt sgtxt rebzg rebzj
                   into corresponding
                   fields of table ibsegpar_fu_1 from bseg
                   where bukrs = itabkpf-bukrs and
                   belnr = itabkpf-belnr and
                   gjahr = itabkpf-gjahr and
                   augbl <> itabkpf-belnr and
                   rebzg <> space and
                   bschl = '25'.
            loop at ibsegpar_fu_1.
    Start insert by Pradeep 20082008
              sort ibsegpar_fu_1 by belnr.
    End insert by Pradeep 20082008
              move-corresponding ibsegpar_fu_1 to itabseg.
              move ibsegpar_fu_1-belnr to itabseg-augbl.
              move ibsegpar_fu_1-rebzg to itabseg-belnr.
              move ibsegpar_fu_1-rebzj to itabseg-gjahr.
    *********to include code to pick the description for partical payment
              select single * from bseg where
                  bukrs = ibsegpar_fu_1-bukrs and
                  belnr = ibsegpar_fu_1-belnr and
                  gjahr = ibsegpar_fu_1-gjahr and
                  augbl <> ibsegpar_fu_1-belnr and
                  rebzg = space and
                  bschl <> '25'.
              move bseg-sgtxt to itabseg-sgtxt.
              clear bseg.
    *********end of code
              itabseg-wrbtr = itabseg-wrbtr * -1.
              itabseg-pswbt = itabseg-pswbt * -1.
              select single budat into lsdat from
                   bkpf where bukrs = ibsegpar_fu_1-bukrs and
                   belnr = ibsegpar_fu_1-rebzg and
                   gjahr = ibsegpar_fu_1-rebzj.
              if sy-subrc = 0.
                move lsdat to itabseg-zfbdt.
              endif.
              append itabseg.
            endloop.
          endif. "Deleted by Pradeep 20082008
        endloop.
        loop at ibsegpar_fu.
          sort ibsegpar_fu by belnr. " insert by pradeep
          move-corresponding ibsegpar_fu to itabseg.
          select bukrs belnr gjahr bschl koart lifnr wrbtr
                 rebzg rebzj sgtxt into corresponding
                 fields of table ibsegpar_fu_1 from bseg
                 where  bukrs = ibsegpar_fu-bukrs and
                 gjahr = ibsegpar_fu-gjahr and
                 augbl = ibsegpar_fu-belnr and  " Pradeep 20082008 Delete
                augbl <> ibsegpar_fu-belnr and " Pradeep 20082008 Insert
                 rebzg = space and
                 bschl = '25'.
          if sy-subrc = 0.
            loop at ibsegpar_fu_1.
              move ibsegpar_fu_1-rebzg to itabseg-rebzg.
              move ibsegpar_fu_1-rebzj to itabseg-rebzj.
            endloop.
            move ibsegpar_fu-belnr to itabseg-augbl.
            move itabseg-rebzg to itabseg-belnr.
            move itabseg-rebzj to itabseg-gjahr.
            itabseg-wrbtr = itabseg-wrbtr * -1.
            itabseg-pswbt = itabseg-pswbt * -1.
            select single budat into lsdat from
                 bkpf where bukrs = ibsegpar_fu-bukrs and
                 belnr = itabseg-rebzj and
                 gjahr = itabseg-rebzj.
            if sy-subrc = 0.
              move lsdat to itabseg-zfbdt.
            endif.
            append itabseg.
            read table itabseg with key
                 belnr = itabseg-rebzg
                 gjahr = itabseg-rebzj
                 bschl = '31' .
            if sy-subrc = 0.
             delete itabseg index sy-tabix. "Deleted by Pradeep 20082108
            endif.
          endif.
        endloop.
    Start insert by Pradeep 20082008
         loop at itabseg.
          if itabseg-belnr = itabseg-augbl.
            delete itabseg.
          elseif itabseg-belnr = ' '.
            delete itabseg.
          endif.
        endloop.
    End insert by Pradeep 20082008

  • How to use Group in Query Print Layout

    Hi All,
    I have prepared a query for fetching all purchase details along with tax code, now I have ordered it on tax code and prepared a query Print Layout,
    Now within this Query Print Lay Out I want to group the tax code and want to add total of some columns at end of every tax code.
    Request to guide how to achieve this.
    Thanking you in advance,
    Samir Gandhi

    We need to use Sort and Group in combination.
    Select the repeatative area and in PLD menu select Sort, then select the column to be sort.
    then in Header / Footer of that respective repeatative area select the fields and put in the group no. in the General.

  • How to use group by in query

    In this query  i want group by item description and quatity sum
    SELECT T0.[Dscription], T0.[Quantity], T0.[OpenSum],  T1.[DocNum], T2.[State] FROM DLN1 T0  INNER JOIN ODLN T1 ON T0.DocEntry = T1.DocEntry, CRD1 T2 WHERE T1.[CardCode] =  T2.[CardCode] AND  T1.[DocNum] Like '1_%%'

    Hi YYREDDY,
    When you use the GROUP clause, all the fields in the SELECT clause must either figure in the GROUP clause or be part of an aggregate function (AVG, SUM, COUNT, ...).
    SELECT
        T0.Dscription, SUM(T0.Quantity), SUM(T0.OpenSum)
    FROM
        DLN1 T0 INNER JOIN
        ODLN T1 ON T0.DocEntry = T1.DocEntry, CRD1 T2
    WHERE
        T1.CardCode = T2.CardCode AND T1.DocNum Like '1_%%'
    GROUP BY
        T0.Dscription
    Regards,
    Vítor Vieira

  • How to use multi select in a query report

    I defined a lov. This lov retuns name and a id. I want to use the result of this multi select in my query.
    I always get invalid number when I choose two items of the select. When I debug I see that the return value of the multi select is 1:2. How can I change the seperator : in , I tried the following but this does't work.
    if :P26_PRODUCTTYPE IS NOT NULL then
    l_sql := l_sql ||' and producttype in
    (REPLACE(:p26_producttype,'':'','','' ))';
    end if;

    as you're finding, multiple values selected from html db multi-select list items (and checkboxes) are stored as a single, colon-delimited string. i explained an easy way to handle this via pl/sql in...
    Multiple select list
    ...that post shows you how to throw the selected values into a pl/sql table and step through them as needed. it also showed how to use an instr to parse through the string if you want to go that route. you could use that same instr logic right in your sql query. so let's say your lov for your multi-select item (P1_MY_MULTISELECT, we'll call it) was defined as...
    select ename, empno from emp order by 1
    ...and your user selected KING, FORD, and JONES. :P1_MY_MULTISELECT would store those values as...
    7839:7902:7566
    ...you could then write a query to return the selected enames with something like...
    select ename, job
    from emp
    where insrt (':'||:P1_MY_MULTISELECT||':',':'||empno||':') != 0
    ...hope this helps,
    raj

  • How to use input box LOV in query panel (search region)

    Hi,
    We are having JDeveloper version 11.1.2.4.0
    In one of the JSF page, we are showing some data (absences).
    Requirement is to add search region at the top so that user can filter the data, based on search parameters like Business Group, Job etc.
    The search parameters are inter-dependent e.g. Job is dependent on Business Group. So when user selects some particular Business Group, Job search field should show jobs for that Business Group only.
    This works fine we use Choice List for both Business Group and Job.
    However since there are huge number of jobs, Job choice list makes page rendering very slow.
    So we tried to use Input box with LOV for Job.
    But now when job is selected in the LOV popup and returned to main page, job search field shows job id instead of job name.
    Please note that our base VO (AbsencesVO) contains JobId attribute. We have added List of Values on JobId, which fetches Job Name through JobVO1 view accessor.
    How to make Job LOV field show selected Job Name instead of ID? Kindly advise.
    Thanks,
    Vivek

    Thanks Timo/Bangaram, for prompt replies
    Timo, the link mentioned by you talks about showing IDs (DepartmentId, ManagerId etc.) in the search region. I need to show names in the form of Input box LOV.
    Bangaram, as per your suggestion I tried using transient JobName attribute. However now when I select any value in the Job LOV popup and return to main page, it shows first Job Name in the Job Name search field.
    Also when I click 'Search' button in Search panel, it shows error - Attempt to set a parameter name that does not occur in the SQL: BindJobName
    Please note that I have added both JobName and JobId in the List configuration as you suggested.
    In View criteria, I have removed previous item (condition) on JobId and added condition on JobName.(This is required because JobId condition shows JobId search field)
    I also tried making JobName dependent on JobId..still same behaviour.
    Kindly advise.
    Thanks,
    Vivek

  • How to use Associative Array in sql query?

    Hello,
    I have a problem on using Associative Array variable on query; and my query is similar to the one below;
    TYPE OTHERGENERICS IS TABLE OF NUMBER(10) INDEX BY BINARY_INTEGER;
    othersGenerics OTHERGENERICS;
    CURSOR cursor_othersGenerics IS
    select master.GENERICCODEID
    from ASMTRG_ARTICLEMASTER master
    join ASMTRG_ARTICLEMAP map on MAP.ARTICLECODEID = MASTER.ID
    group by MASTER.GENERICCODEID
    minus
    select FGG.GENERICCODEID
    from asmtrg_icfocusgroup fg
    join asmtrg_icfocusgrpchannel fgc on FGC.GROUPID = FG.ID and fgc.isactive=1
    join asmtrg_icfocusgengroup fgg on FGG.GROUPID = FG.ID and FGg.ISACTIVE=1
    where fgc.channelid=1 and fg.isactive = 1
    group by FGG.GENERICCODEID;
    BEGIN
    OPEN cursor_othersGenerics;
    FETCH cursor_othersGenerics BULK COLLECT INTO othersGenerics;
    CLOSE cursor_othersGenerics;
    SELECT icfrd.*,
    CASE
    WHEN EXISTS(select ta.genericcodeid from <???XXX???> ta where ta.genericcodeid = icfgrp.genericcodeid) THEN -1
    ELSE icfrd.icfgroupid
    END CLASSIFICATION
    FROM ASMTRGVIW_ICFOCUSREPORTDATA icfrd
    LEFT JOIN ASMTRG_ICFOCUSGROUP icfgrp on icfrd.ICFGROUPID = icfgrp.ID
    WHERE (channelId IS NULL OR icfrd.CHANNELID = channelId)
    AND (asmCodeId IS NULL OR icfrd.ASMCODEID = asmCodeId)
    AND (yearId IS NULL OR icfrd.YEARID = yearId)
    AND (monthId IS NULL OR icfrd.MONTHID = monthId)
    END;
    By the way this is a part of my function.
    The "othersGenerics" is my associative array variable and <???XXX???> is the place where I need to use my "othersGenerics" array to check. So far I've tried
    "select ta.genericcodeid from table(cast(otherGenerics as OTHERGENERICS)) ta where ta.genericcodeid = icfgrp.genericcodeid",
    "select ta.genericcodeid from table(otherGenerics) ta where ta.genericcodeid = icfgrp.genericcodeid",
    "select ta.genericcodeid from otherGenerics ta where ta.genericcodeid = icfgrp.genericcodeid"
    and these are not working.
    What is your suggestions?

    Your type will have to be created as an independent object in your schema. So CREATE TYPE cannot be in your function declaration, it has to be outside it. (And then the line inside your declaration that defines the type will have to be removed.)
    But now I can see that you use this array as a kind of "temporary lookup table" - you populate the array and then use it for lookup in your select statement. An alternative way of doing this could be like this completely without arrays:
    with othergenerics as (
      select master.GENERICCODEID
      from ASMTRG_ARTICLEMASTER master
      join ASMTRG_ARTICLEMAP map on MAP.ARTICLECODEID = MASTER.ID
      group by MASTER.GENERICCODEID
      minus
      select FGG.GENERICCODEID
      from asmtrg_icfocusgroup fg
      join asmtrg_icfocusgrpchannel fgc on FGC.GROUPID = FG.ID and fgc.isactive=1
      join asmtrg_icfocusgengroup fgg on FGG.GROUPID = FG.ID and FGg.ISACTIVE=1
      where fgc.channelid=1 and fg.isactive = 1
      group by FGG.GENERICCODEID
    SELECT icfrd.*,
    CASE
    WHEN EXISTS(select ta.genericcodeid from othergenerics ta where ta.genericcodeid = icfgrp.genericcodeid) THEN -1
    ELSE icfrd.icfgroupid
    END CLASSIFICATION
    FROM ASMTRGVIW_ICFOCUSREPORTDATA icfrd
    LEFT JOIN ASMTRG_ICFOCUSGROUP icfgrp on icfrd.ICFGROUPID = icfgrp.ID
    WHERE (channelId IS NULL OR icfrd.CHANNELID = channelId)
    AND (asmCodeId IS NULL OR icfrd.ASMCODEID = asmCodeId)
    AND (yearId IS NULL OR icfrd.YEARID = yearId)
    AND (monthId IS NULL OR icfrd.MONTHID = monthId)
    ...The with clause (subquery factoring) you can think of as a kind of temp table called othergenerics created "on-the-fly".
    The optimizer may decide to actually create a temp table for you and use in the lookup, or it may decide to rewrite the query into suitable joins or nested loops or hashing - whatever the optimizer decides will be the optimal way of doing things :-)
    So unless you use your array other places in your function, I would recommend dropping the array completely, skip populating an array, and instead use a with clause for your temporary lookup.

Maybe you are looking for