Query with Union to Show Ship to of Both Supplier & Customer BP's

Hi Guys,
I need to do a query that I can use in a formatted search, that will allow me to select from a list that shows both BP Ship to Addresses from The Customer and Supplier Tables. I know I have to use a union, however I have no clue where to start with this - would someone be so kind as to point me in the right directions please.
Kind regards
Sean Martin
Edited by: Sean Martin on Apr 18, 2011 5:20 PM

Hello Sean - I see you are new - let me welcome you to the SAP B1 forums...
Maybe you do have the wrong forum as Julie suggests above, but maybe it is a bit perplexing as to what you need in an SAP B1 sense...
1.  Let us know where you would be using the formatted search (in the Sales documents? - in the Purchasing documents?) - OR - maybe give a business scenario...
2.  Let us know what field the results would populate...
3.  Are you looking for two formatted searches - one to be used with suppliers and one to to be used for customers - OR - do you want the formatted search to list all Ship-To addresses combined into one list?
4.  A statement of UNION might not be needed!
5.  The tables to reference in the formatted search are OCRD and CRD1.
That way you can help us help you better...again, wecome and...
Regards - Zal

Similar Messages

  • Query with union

    Hi,
    I have three table:
    Candidates: (candidate_id primary key)
    Purhcase_orders: (Po_number primary key)
    Bids: (bid_number primary key)
    Just wanted to retrieve candidate information like candidate_id, first_name etc, along with count of purchase orders issued against this candidate and count of bid_number.
    For that I have written below query:
    query - 1:
    SELECT CANDIDATE_ID,
    INITCAP (first_name) FIRST_NAME,
    +(SELECT COUNT (DISTINCT bid_number)+
    FROM bids
    WHERE BIDS.CANDIDATE_ID = cand.candidate_id)
    BID_COUNT,
    +(SELECT COUNT (DISTINCT po_number)+
    FROM purchase_orders po
    WHERE PO.CONTRACTEE_ID = cand.candidate_id)
    PO_COUNT,
    +'Y' match_flag,+
    DECODE ( (SELECT candidate_id
    FROM v_ineligible_candidates vic
    WHERE VIC.CANDIDATE_ID = cand.candidate_id),
    NULL, 'N',
    +'Y')+
    INELIGIBLE_FLAG
    FROM candidates cand
    Based on business requirement, need to create another set of query (query -2) same like above. In that we have some decode statements to calculate match_flag, then need to perform UNION operation between query -1 and query -2.
    have around 130563 number of rows in candidates table.
    Individually both queries are taking 500 msec.
    But when I have used union, it didnt give result for atleast 60 sec. Then I cancelled execution.
    Execution plan for the final query with UNION: (final cost)
    Cost: 2,873  Bytes: 9,130,170  Cardinality: 260,862                
    Please help me in this issue.
    Why its taking that much time in union.
    Please correct my mistake and suggest me in this query.
    UNION ALL is running but not UNION.
    Thanks in advance

    Please post complete Explain Plans.
    To get detailed information of Explain Plan use
    explain plan for
    your_query;
    select *
      from table(dbms_xplan.display(null, null, 'ALL'));Post it alongwith below details between {noformat}{noformat} (exactly as specified) tags to preserve formatting and ease of understanding.
    On your requirement,
    Using UNIONALL you will get two set of rows, with UNION you might get a single row if your MATCH_FLAG are same for both queries. Use of either, has to meet your requirements than to meet your performance. If it is Business Acceptable, then look for performance and tuning.
    If you could do the folllowing, it might be helpful for you.
    1. Post the Sample table structure (Table information of Candidates should suffice) in a Create Table/With Sub-Query clause.
    2. Sample Data in Insert Into/With Sub-Query format.
    3. Expected Outcome based on Sample data
    4. The Explain Plan of your Queries as requested above.
    Reason of asking these details are, there might be a way to avoid Hitting the table Twice and avoid use of UNION/UNIONALL clauses.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Select query with UNION clause in database adapter

    Friends,
    I have got a SQL query with two UNION clause withing it. like
    select a,b,c
    from a
    union
    select a,b,c
    from b
    The schema generated is like below in sequence
    <element>a</element>
    <element>b</element>
    <element>c</element>
    <element>a</element>
    <element>b</element>
    <element>c</element>
    So, the columns from different select queries joined with UNION clause are all appeared in schema instead of the distinct columns.
    Is there any way around to solve this issue ? or will need to with DB function/procedure.

    I think I know what you are saying but your example doesn't make sense, your SQL should produce something like
    I had to change a, b, c with elementA, elementB, elementC as a and b are reserved html tags.
    <elementA>DateA</elementA>
    <elementB>DataB</elementB>
    <elementC>DataC</elementC>
    ...What is the result of the query when you run it in SQLPlus? Is it what you expect?
    cheers
    James

  • Query with UNION option

    Hi ,
    I have one partition table.The partitions are created datewise.Now when i have to fire select query on that talble i am firing below querry
    Select count(1) from table A where createdate between ('01-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('01-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    Above query will scan 1 day partition.
    now if i want to fetch records from whole month ,it will scan 31 partition one by one.
    Select count(1) from table A where createdate between ('01-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('31-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    Now if i change the query by writing another way which will scan partition parallely.
    Select count(1) from table A where createdate between ('01-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('01-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    union
    Select count(1) from table A where createdate between ('02-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('02-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    union
    Select count(1) from table A where createdate between ('03-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('03-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    union
    till
    Select count(1) from table A where createdate between ('31-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('31-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    Is it possible that i can make query by passing different month in above union query .
    Month can be dynamic, and above select can be take the values by passing the month.
    kindly guide me
    =======

    I hear you. But can you demonstrate, instead of just telling?
    Else, I'll be guessing, that you are just guessing. And I am inclined to guess that your guess is wrong.
    But, I could be guessing wrong, of course. (And week-ends I am not online to test it myself)
    Start by showing the table, ddl. Is it parallel, noparallel? - And then show the plans for both queries.
    And how did you come to that conclusion of "one by one" vs "in parallel"?
    Regards
    Peter

  • Join query with union

    Hi all
    I have two queries and i want to join this two query
    The report column should be like this
    item_number WK_30  WE_311st query
    select
    re.item_number,
    nvl(le.quantity,0) - nvl(re.quantity,0) WK_30
    from BACKLOG_WEEK_WH_AFTR_ATP le, BACKLOG_ATP_GT_CW_IN re
    where le.item_number =re.item_number
    and to_number(substr(re.year_week,-2,2)) = to_number(to_char(sysdate,'IW'))+12nd query
    select
    re.item_number,
    nvl(le.quantity,0) - nvl(re.quantity,0) WK_31
    from BACKLOG_WEEK_WH_AFTR_ATP le, BACKLOG_ATP_GT_CW_IN re
    where le.item_number =re.item_number
    and to_number(substr(re.year_week,-2,2)) = to_number(to_char(sysdate,'IW'))+2Thanks in advance
    Regards

    Hello
    It sounds like you need a cumulative sum, in which case I think you'll need to go with analytics. If you could supply create table statements, some sample data and a clear example of the output you expect, it would be easier to put something together. However, I think the statement below should work although it is untested.
    SELECT
        item_number,
        plus_1,
        plus_2,
        plus_3,
        plus_4,
        plus_5,
        plus_6,
        plus_7,
        plus_8,
        plus_9,
        plus_10,
        plus_11,
        plus_12,
        plus_13
    FROM
        (   select
                re.item_number,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+1, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_1,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+2, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_2,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+3, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_3,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+4, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_4,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+5, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_5,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+6, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_6,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+7, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_7,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+8, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_8,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+9, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_9,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+10, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_10,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+11, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_11,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+12, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_12,
                sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+13, nvl(le.quantity,0) - nvl(re.quantity,0),0))
                OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_13,
                ROW_NUMBER() OVER(PARTITION BY re.item_number) rn
            from
                BACKLOG_WEEK_WH_AFTR_ATP le, BACKLOG_ATP_GT_CW_IN re
            where
                le.item_number =re.item_number
            and
                and to_number(substr(re.year_week,-2,2)) in
                (   to_number(to_char(sysdate,'IW'))+1,
                    to_number(to_char(sysdate,'IW'))+2,
                    to_number(to_char(sysdate,'IW'))+3,
                    to_number(to_char(sysdate,'IW'))+4,
                    to_number(to_char(sysdate,'IW'))+5,
                    to_number(to_char(sysdate,'IW'))+6,
                    to_number(to_char(sysdate,'IW'))+7,
                    to_number(to_char(sysdate,'IW'))+8,
                    to_number(to_char(sysdate,'IW'))+9,
                    to_number(to_char(sysdate,'IW'))+10,
                    to_number(to_char(sysdate,'IW'))+11,
                    to_number(to_char(sysdate,'IW'))+12,
                    to_number(to_char(sysdate,'IW'))+13
    WHERE
        rn = 1HTH
    David

  • Urgent! How to use push_pred to optimize query with UNION in 10g?

    Hi,
    We are facing slow query performance in 10g database.
    Appreciate if anyone could advise on how to optimize the performance by using push pred?
    Or is there any other ways.
    Thanks in advance.
    Cheers,
    SC

    dont post duplicate post

  • Problems with Union statement

    Hi,
    I'm writing an application with jdbc. I'm using Oracle Release 8.0.5.0.0, j2re 1.4.2_06.
    The query with UNION produces a resultSet with no record while if I execute the same query with Oracle SQL Worksheet I've one record.
    This is the code with a sample query:
    Class.forName(jdbcDriver).newInstance();
    Connection c = DriverManager.getConnection(dbUrl, "**", "**");
    Statement st = c.createStatement();
    String query = "(select fam from people where id=1711) union (select fam from family where fam=397)";
    ResultSet rs = st.executeQuery(query);
    if(rs!=null){
    while(rs.next()){...}
    rs.next is false but I know It's not correct!
    I dont get any exception and until I didn't use the UNION statement all worked fine!
    Please help me, thanks

    ok... I'm replying to myself:
    It works if I write the query as follow:
    "select fam from people where id=1711 union select fam from family where fam=397"
    without '( ... )' !
    bye

  • GRPO QUERY WITH FREIGHT

    Dear All
    When i run the following GRPO query (with freight) it shows me 2 lines when there is multiple freight lines in the freight screen. Can anybody guide where the changes is to be made in this query.
    SELECT T0.[DocNum] as 'GRPO Number',T0.[DocDate] as 'GRPO Date', t0.DocDueDate as 'Inspected Date',T0.[CardName]  as 'Vendor Name', T0.[Project] as 'JOB Number', T0.U_PRNo as 'PRS Number',T0.U_BILL as 'Bill Number',T0.U_DC as 'DC Number',t0.u_doc_ref as 'Document Reference 1',T1.[BaseRef] as 'PO Number',sum (t1.linetotal) as 'Basic', T2.LineTotal AS 'Freight & P&F',
    SUM(T3.TAXSUM) AS 'BEDAmt',
    sum(t4.taxsum) as 'ECessAmt',
    sum(t5.taxsum) as 'HECess Amt',
    sum(t6.taxsum) as 'BED on Freight',
    sum(t7.taxsum) as 'CESS on Freight',
    sum(t8.taxsum) as 'HECess on Freight',
    sum(t9.taxsum) as 'VAT ON Freight Amt',
    sum(t10.taxsum) as 'CST ON Freight Amt',
    sum(t11.taxsum) as 'VAT Amt',
    sum(t12.taxsum) as 'VAT along with Excise Amt',
    sum(t13.taxsum) as 'CST Amt',
    sum(t14.taxsum) as 'CST along with Excise Amt',
    sum(t15.taxsum) as 'AED Amt',
    T0.Doctotal as 'Total Amount of GRPO'
    FROM OPDN T0 INNER JOIN PDN1  T1 ON T0.DocEntry = T1.DocEntry
    LEFT OUTER JOIN PDN3 T2 ON T2.DocEntry = T1.DocEntry
    LEFT OUTER JOIN PDN4 T3 ON T3.DocEntry=T0.DocEntry and T0.DocEntry=T3.DocEntry AND T3.staType=-90 AND T1.LineNum=T3.LineNum
    LEFT OUTER JOIN PDN4 T4 ON T4.DocEntry=T0.DocEntry and T0.DocEntry=T4.DocEntry AND T4.staType=-60 AND T1.LineNum=T4.LineNum
    LEFT OUTER JOIN PDN4 T5 ON T5.DocEntry=T0.DocEntry and T0.DocEntry=T5.DocEntry AND T5.staType=7 AND T1.LineNum=T5.LineNum
    LEFT OUTER JOIN PDN4 T6 ON T6.DocEntry=T0.DocEntry and T0.DocEntry=T6.DocEntry AND T6.staType=22 AND T1.LineNum=T6.LineNum
    LEFT OUTER JOIN PDN4 T7 ON T7.DocEntry=T0.DocEntry and T0.DocEntry=T7.DocEntry AND T7.staType=23 AND T1.LineNum=T7.LineNum
    LEFT OUTER JOIN PDN4 T8 ON T8.DocEntry=T0.DocEntry and T0.DocEntry=T8.DocEntry AND T8.staType=24 AND T1.LineNum=T8.LineNum
    LEFT OUTER JOIN PDN4 T9 ON T9.DocEntry=T0.DocEntry and T0.DocEntry=T9.DocEntry AND T9.staType=25 AND T1.LineNum=T9.LineNum
    LEFT OUTER JOIN PDN4 T10 ON T10.DocEntry=T0.DocEntry and T0.DocEntry=T10.DocEntry AND T10.staType=26 AND T1.LineNum=T10.LineNum
    LEFT OUTER JOIN PDN4 T11 ON T11.DocEntry=T0.DocEntry and T0.DocEntry=T11.DocEntry AND T11.staType=1 AND T1.LineNum=T11.LineNum
    LEFT OUTER JOIN PDN4 T12 ON T12.DocEntry=T0.DocEntry and T0.DocEntry=T12.DocEntry AND T12.staType=14 AND T1.LineNum=T12.LineNum
    LEFT OUTER JOIN PDN4 T13 ON T13.DocEntry=T0.DocEntry and T0.DocEntry=T13.DocEntry AND T13.staType=4 AND T1.LineNum=T13.LineNum
    LEFT OUTER JOIN PDN4 T14 ON T14.DocEntry=T0.DocEntry and T0.DocEntry=T14.DocEntry AND T14.staType=13 AND T1.LineNum=T14.LineNum
    LEFT OUTER JOIN PDN4 T15 ON T15.DocEntry=T0.DocEntry and T0.DocEntry=T15.DocEntry AND T15.staType=-80 AND T1.LineNum=T15.LineNum
    WHERE T0.[Project] between '[%0]' and '[%1]' or T0.[DocDate] between '[%2]' and '[%3]'
    GROUP BY T0.[DocDate], T0.[DocNum],T0.[CardName], T0.[Project], T1.[BaseRef], T2.[LineTotal],T0.U_PRNo,t0.DocDueDate,T0.U_BILL,T0.U_DC,t0.U_DOC_REF,T0.Doctotal
    REGARDS
    KARTHIK

    Hello Karthik,
    Try This
    declare @todate as datetime
    declare @enddate as datetime
    SELECT @todate= /*min(T0.DocDate) FROM OINM T0 WHERE T0.DocDate=*/ '[%0]'
    SELECT @enddate= /*max(T0.DocDate) FROM OINM T0 WHERE T0.DocDate=*/'[%1]'
    select DISTINCT a.Docnum as "GRPO No" ,a.docdate AS "GRPO Date" ,
    a.cardname as "Supplier Name" ,a.DocDueDate ,
    (select sum(LineTotal) from PDN1 where docentry = a.docentry)as "Basic Value" ,
    (select sum(LineTotal) from PDN3 where docentry = a.docentry)as "Freight & P&F Am" ,a.DiscSum as 'Discount',
    (Select sum(taxsum) FROM PDN4 where docentry = a.docentry and statype=-90) as "BED" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=-60) as "Cess" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=7) as "HeCess" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=-80) as "AED" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=13) as "CST along with Excise Amt" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=4) as "CST" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=1) as "VAT" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=14) as "VAT along with Excise Amt" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=26) as "CST on Freight Amt" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=25) as "VAT on Freight Amt" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=22) as "BED on Freight Amt" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=23) as "CESS on Freight Amt" ,
    (Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=24) as "HECESS on Freight Amt" ,
    A.DocTotal as "Net Value"
    FROM OPDN A left OUTER JOIN PDN3 B ON A.DOCENTRY = B.DOCENTRY left OUTER JOIN PDN4 C
    ON A.DOCENTRY = C.DOCENTRY left outer join PDN3 h on A.DocEntry = h.DocEntry left outer join
    PDN1 d on a.docentry = d.docentry left outer join crd7 e on a.cardcode = e.cardcode Left Outer Join
    oitm g On d.ItemCode=g.ItemCode left outer join ochp f on f.absentry= g.chapterid where a.Docdate >=@todate
    and a.Docdate <=@enddate and g.itemcode=d.itemcode ORDER BY A.DOCNUM
    Regards:
    Balaji.S

  • How do I create a folder or report from a query with a union and parameters

    I have created folders with unions but I am having difficulty coverting a query with a union and parameters.
    The following works great in SQL*Developer without parameters, but I want to change to use parameters for the year and quarter and use it in Discoverer:
    SELECT TO_CHAR(NVL(AV.TAX_ID,999999999),'000000000') FEID,
      AV.FIRM_NAME VENDOR_NAME,
      AV.BIDCLASS CONTRACT_CODES,
      AV.AWAMT AWARD_AMOUNT,
      AV.SOL_MODE FORMAL_INFORMAL,
      AV.CERT BUSINESS_ENTITY,
      AV.ETHNICITY ETHNICTY,
      AV.PO_NUMBER_FORMAT CONTRACT,
      SUM(VP.INVOICE_AMOUNT) AMOUNT_PAID_$
    FROM CONFIRM.VSTATE_PAID_AWARD_VENDORS AV,
      CONFIRM.VSTATE_VENDOR_PAYMENTS VP
    WHERE ( ( AV.PO_NUMBER = VP.PO_NUMBER
    AND AV.VENDOR_ID       = VP.VENDOR_ID ) )
    AND (TO_CHAR(VP.PAYMENT_DATE,'Q') = '4')
    AND ( TO_CHAR(VP.PAYMENT_DATE,'YYYY') = '2009' )
    GROUP BY TO_CHAR(NVL(AV.TAX_ID,999999999),'000000000'),
      AV.FIRM_NAME,
      AV.BIDCLASS,
      AV.AWAMT,
      AV.SOL_MODE,
      AV.CERT,
      AV.ETHNICITY,
      AV.PO_NUMBER_FORMAT
      union
    SELECT TO_CHAR(NVL(AV2.TAX_ID,999999999),'000000000') FEID,
      AV2.FIRM_NAME VENDOR_NAME,
      AV2.BIDCLASS CONTRACT_CODES,
      AV2.AWAMT AWARD_AMOUNT,
      AV2.SOL_MODE FORMAL_INFORMAL,
      AV2.CERT BUSINESS_ENTITY,
      AV2.ETHNICITY ETHNICTY,
      AV2.PO_NUMBER_FORMAT CONTRACT,
      0 AMOUNT_PAID_$
    FROM CONFIRM.VSTATE_PAID_AWARD_VENDORS AV2
    WHERE
    not exists (SELECT 'X'
                  FROM CONFIRM.VSTATE_VENDOR_PAYMENTS VP2
                 WHERE av2.po_number = vp2.po_number
                       AND (TO_CHAR(VP2.PAYMENT_DATE,'Q') = '4')
                       AND ( TO_CHAR(VP2.PAYMENT_DATE,'YYYY') = '2009' ))
    AND (TO_CHAR(AV2.AWDATE,'Q') = '4')
    AND (to_CHAR(AV2.AWDATE,'YYYY') = '2009')
    GROUP BY TO_CHAR(NVL(AV2.TAX_ID,999999999),'000000000'),
      AV2.FIRM_NAME,
      AV2.BIDCLASS,
      AV2.AWAMT,
      AV2.SOL_MODE,
      AV2.CERT,
      AV2.ETHNICITY,
      AV2.PO_NUMBER_FORMAT Can someone provide a solution?
    Thank you,
    Robert

    Hi,
    You can take the parameters to the select so that you will be able to create conditions over them.
    Try to use this SQL instead of your and in the discoverer workbook create the conditions and parameters:
    SELECT TO_CHAR(NVL(AV.TAX_ID,999999999),'000000000') FEID,
    AV.FIRM_NAME VENDOR_NAME,
    AV.BIDCLASS CONTRACT_CODES,
    AV.AWAMT AWARD_AMOUNT,
    AV.SOL_MODE FORMAL_INFORMAL,
    AV.CERT BUSINESS_ENTITY,
    AV.ETHNICITY ETHNICTY,
    AV.PO_NUMBER_FORMAT CONTRACT,
    TO_CHAR(VP.PAYMENT_DATE,'YYYY') P_YEAR,
    TO_CHAR(VP.PAYMENT_DATE,'Q') P_QTR
    SUM(VP.INVOICE_AMOUNT) AMOUNT_PAID_$
    FROM CONFIRM.VSTATE_PAID_AWARD_VENDORS AV,
    CONFIRM.VSTATE_VENDOR_PAYMENTS VP
    WHERE ( ( AV.PO_NUMBER = VP.PO_NUMBER
    AND AV.VENDOR_ID = VP.VENDOR_ID ) )
    --AND (TO_CHAR(VP.PAYMENT_DATE,'Q') = '4')*
    --AND ( TO_CHAR(VP.PAYMENT_DATE,'YYYY') = '2009' )*
    GROUP BY TO_CHAR(NVL(AV.TAX_ID,999999999),'000000000'),
    AV.FIRM_NAME,
    AV.BIDCLASS,
    AV.AWAMT,
    AV.SOL_MODE,
    AV.CERT,
    AV.ETHNICITY,
    AV.PO_NUMBER_FORMAT ,
    TO_CHAR(VP.PAYMENT_DATE,'YYYY') P_YEAR,
    TO_CHAR(VP.PAYMENT_DATE,'Q') P_QTR
    union
    SELECT TO_CHAR(NVL(AV2.TAX_ID,999999999),'000000000') FEID,
    AV2.FIRM_NAME VENDOR_NAME,
    AV2.BIDCLASS CONTRACT_CODES,
    AV2.AWAMT AWARD_AMOUNT,
    AV2.SOL_MODE FORMAL_INFORMAL,
    AV2.CERT BUSINESS_ENTITY,
    AV2.ETHNICITY ETHNICTY,
    AV2.PO_NUMBER_FORMAT CONTRACT,
    TO_CHAR(VP.PAYMENT_DATE,'YYYY') P_YEAR,
    TO_CHAR(VP.PAYMENT_DATE,'Q') P_QTR
    0 AMOUNT_PAID_$
    FROM CONFIRM.VSTATE_PAID_AWARD_VENDORS AV2
    WHERE
    not exists (SELECT 'X'
    FROM CONFIRM.VSTATE_VENDOR_PAYMENTS VP2
    WHERE av2.po_number = vp2.po_number
    AND (TO_CHAR(VP2.PAYMENT_DATE,'Q') = TO_CHAR(VP.PAYMENT_DATE,'Q') )
    AND ( TO_CHAR(VP2.PAYMENT_DATE,'YYYY') = TO_CHAR(VP.PAYMENT_DATE,'YYYY') ))
    --AND (TO_CHAR(AV2.AWDATE,'Q') = '4')*
    --AND (to_CHAR(AV2.AWDATE,'YYYY') = '2009')*
    GROUP BY TO_CHAR(NVL(AV2.TAX_ID,999999999),'000000000'),
    AV2.FIRM_NAME,
    AV2.BIDCLASS,
    AV2.AWAMT,
    AV2.SOL_MODE,
    AV2.CERT,
    AV2.ETHNICITY,
    AV2.PO_NUMBER_FORMAT,
    TO_CHAR(VP.PAYMENT_DATE,'YYYY') P_YEAR,
    TO_CHAR(VP.PAYMENT_DATE,'Q') P_QTR
    Tamir

  • Creating Query with dynamic columns to show results

    Hi experts,
    I need to know how to create a query with dynamic columns. Meaning, I don't want to create a query with fixed columns representing the 12 periods of the fiscal year to show me actuals as the fiscal year proceeds.
    For example, if I am currently in the middle of period 3 (March) of a fiscal year, when I execute the query, I need it to automatically only show me the 'Actuals' for periods 1 and 2, without seeing the columns from periods 3 to 12 showing blank.
    Then when I am in the middle period 5 (May) the query should ONLY show me the columns for periods 1 to 4 'Actuals', no results should be shown for periods 5 to 12 yet, and I don't want to even see blank columns for period 6 to 12.
    How do I define my columns, to achieve this.
    Maximum points will be awarded.
    Thanks Everyone.

    Hi Josh,
    I'm having a little difficuluty understanding what should be included in my restricted key figures.
    The time characteristics that I have available to use are:
    0FISCPER3 (posting period)
    0FISCYEAR (fiscal year), currently using SAP EXIT to default current fiscal year.
    0FISCVARNT (fiscal year variant).
    In addition, I have the following characteristics available to be used in the columns:
    Value type (10)
    version (currently I'm using variable for it)
    Currency type (020)
    Currency (USD).
    Can you explain what my restricted key figure should be based on and how it should look.
    I tried to create a restircted key figure using 0AMOUNT, and 0FISCPER3. For 0FISCPER3  I created a range from 1 to previous period (using SAP EXIT that supplied previous period).I also had value type, version, currency type, and currency included in that restricted key figure.Then when I tried to drag 0FISCPER3 under the restricted key figure once again, it wouldn't let me, probably because I've already used 0FISCPER3 in the restricted key figure.
    Please let me know if my explanation is not clear.
    Your step by step help would be great.
    Thanks
    Edited by: Ehab Mansour on Sep 23, 2008 2:40 PM

  • SQL query in SQL_REDO Logminor showing where clause with ROWID

    SQL query in SQL_REDO Logminor showing where clause with ROWID. I dont wanted to use rowid but wanted to use actual value.
    OPERATION SQL_REDO SQL_UNDO
    DELETE delete from "OE"."ORDERS" insert into "OE"."ORDERS"
    where "ORDER_ID" = '2413' ("ORDER_ID","ORDER_MODE",
    and "ORDER_MODE" = 'direct' "CUSTOMER_ID","ORDER_STATUS",
    and "CUSTOMER_ID" = '101' "ORDER_TOTAL","SALES_REP_ID",
    and "ORDER_STATUS" = '5' "PROMOTION_ID")
    and "ORDER_TOTAL" = '48552' values ('2413','direct','101',
    and "SALES_REP_ID" = '161' '5','48552','161',NULL);
    and "PROMOTION_ID" IS NULL
    and ROWID = 'AAAHTCAABAAAZAPAAN';
    DELETE delete from "OE"."ORDERS" insert into "OE"."ORDERS"
    where "ORDER_ID" = '2430' ("ORDER_ID","ORDER_MODE",
    and "ORDER_MODE" = 'direct' "CUSTOMER_ID","ORDER_STATUS",
    and "CUSTOMER_ID" = '101' "ORDER_TOTAL","SALES_REP_ID",
    and "ORDER_STATUS" = '8' "PROMOTION_ID")
    and "ORDER_TOTAL" = '29669.9' values('2430','direct','101',
    and "SALES_REP_ID" = '159' '8','29669.9','159',NULL);
    and "PROMOTION_ID" IS NULL
    and ROWID = 'AAAHTCAABAAAZAPAAe';
    Please let me know solution/document which will convert SQL redo rowid value with actual value.
    Thanks,

    Please enclose your output within tag so that people here can read it easily and help you. Also the reason that why you want to remove rowid?
    Salman
    Edited by: Salman Qureshi on Mar 20, 2013 3:53 PM                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Report with Union

    Hello Gurus
    I have a report with UNION of 3 criteria and the result i am getting is one of the columns is a union of 3 columns like Age Group,Gender and Race and here the problem is i need to show them in order Race first, Age Group, Gender now it is showing in sorting order even though i cleared sort on all the columns 65+,75+,85+, Asain, Black,Female,Hispanic,Male instead i want the column to show me Asian, Black,Hispanic, 65+,75+,85+,Female, male also in that table i want to make the table line thicker after race category and Age Group
    Thanks
    RC

    user1146711 wrote:
    Hello Gurus
    I have a report with UNION of 3 criteria and the result i am getting is one of the columns is a union of 3 columns like Age Group,Gender and Race and here the problem is i need to show them in order Race first, Age Group, Gender now it is showing in sorting order even though i cleared sort on all the columns 65+,75+,85+, Asain, Black,Female,Hispanic,Male instead i want the column to show me Asian, Black,Hispanic, 65+,75+,85+,Female, male also in that table i want to make the table line thicker after race category and Age Group
    Thanks
    RCTry this:
    1) In each of your three separate queries, add another column.
    2) Create BINS according to how you want the final report be sorted: Asian = '1', Black = '2', etc...
    3) Sort on this column in the combined query.
    Since each query will have the proper number assigned to the group, the report will sort as you wish...

  • Problem in Query with JOIN Function in OCRD CRD1 OCPR tables

    Hello Dear Forum Users,
    I want to make a query which shows me per business partner from OCRD - Addres; CRD1 - Delivery Address and from OCPR - Contactperson information
    Is it possible to show it in one row per Business Partner. Now I get (the classic problem) of several rows and a duplication of the contact persons per (delivery) address.
    My query is:
    SELECT T0.[CardCode], T0.[CardName], T1.[Address], T1.[Street], T1.[ZipCode], T1.[City], T1.[Country], T1.[U_TelNr], T1.[U_MobNr], T1.[U_OpenTijd], T1.[U_LosIns_1], T1.[U_LosIns_2],T2.[Title],  T2.[Name] as 'Voornaam', T2.[Address] as 'Achternaam', T2.[Position] as 'Functie', T2.[Tel1], T2.[Cellolar], T2.[E_MailL], T2.[BirthDate] FROM OCRD T0 LEFT OUTER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode LEFT OUTER JOIN OCPR T2 ON T0.CardCode = T2.CardCode
    Can you help me ?
    Jos Dielemans - Maastricht
    Edited by: J. Dielemans on Apr 29, 2011 4:28 PM
    Changed the query with Left Outer Join

    I have found the solution myself:
    By using the Union All function I could combine two queries. Here is the result:
    SELECT
    T0.[CardCode], T0.[CardName], T1.[Address] , T1.[Street], T1.[ZipCode], T1.[City], T1.[Country], T1.[U_TelNr], T1.[U_OpenTijd] , T1.[U_LosIns_1] , T1.[U_LosIns_2]'
    FROM OCRD T0 LEFT OUTER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode
    WHERE T0.[CardCode] >= 'D00000'
    Union all
    SELECT
    T0.[CardCode], T0.[CardName], T2.[Position], T2.[Tel1], T2.[Title],  T2.[Name], T2.[Address], T2.[Position], T2.[Tel1], T2.[Cellolar], T2.[E_MailL]
    FROM OCRD T0 LEFT OUTER JOIN OCPR T2 ON T0.CardCode = T2.CardCode
    WHERE T0.[CardCode] >= 'D00000'
    Order by 1
    Now i got the result I was looking for.

  • SQL query with Bind variable with slower execution plan

    I have a 'normal' sql select-insert statement (not using bind variable) and it yields the following execution plan:-
    Execution Plan
    0 INSERT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=148)
    1 0 HASH JOIN (Cost=7 Card=1 Bytes=148)
    2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=4 Card=1 Bytes=100)
    3 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=3 Card=1)
    4 1 INDEX (FAST FULL SCAN) OF 'TABLEB_IDX_003' (NON-UNIQUE)
    (Cost=2 Card=135 Bytes=6480)
    Statistics
    0 recursive calls
    18 db block gets
    15558 consistent gets
    47 physical reads
    9896 redo size
    423 bytes sent via SQL*Net to client
    1095 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    55 rows processed
    I have the same query but instead running using bind variable (I test it with both oracle form and SQL*plus), it takes considerably longer with a different execution plan:-
    Execution Plan
    0 INSERT STATEMENT Optimizer=CHOOSE (Cost=407 Card=1 Bytes=148)
    1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=3 Card=1 Bytes=100)
    2 1 NESTED LOOPS (Cost=407 Card=1 Bytes=148)
    3 2 INDEX (FAST FULL SCAN) OF TABLEB_IDX_003' (NON-UNIQUE) (Cost=2 Card=135 Bytes=6480)
    4 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=2 Card=1)
    Statistics
    0 recursive calls
    12 db block gets
    3003199 consistent gets
    54 physical reads
    9448 redo size
    423 bytes sent via SQL*Net to client
    1258 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    55 rows processed
    TABLEA has around 3million record while TABLEB has 300 records. Is there anyway I can improve the speed of the sql query with bind variable? I have DBA Access to the database
    Regards
    Ivan

    Many thanks for your reply.
    I have run the statistic already for the both tableA and tableB as well all the indexes associated with both table (using dbms_stats, I am on 9i db ) but not the indexed columns.
    for table I use:-
    begin
    dbms_stats.gather_table_stats(ownname=> 'IVAN', tabname=> 'TABLEA', partname=> NULL);
    end;
    for index I use:-
    begin
    dbms_stats.gather_index_stats(ownname=> 'IVAN', indname=> 'TABLEB_IDX_003', partname=> NULL);
    end;
    Is it possible to show me a sample of how to collect statisc for INDEX columns stats?
    regards
    Ivan

  • Using sql query with parameter

    OK, I can't find any docs on this. I can insert a parameter, but how do I insert that into the sql query?

    Your first post asked how to insert a paremeter into a SQL. My example shows a value read query with a SQL function, but any SQL will work with any Query in the same pattern.
    a) You call the query with session.executeQuery(query, vectorOfArguments);
    b) You use #argument in the SQL string and then query.addArgument("argument");
    c) You pass them in a Vector of the order in which you do the addArgument's.
    - Don

Maybe you are looking for