Query with additional condition

select * from (select  b.account, f.company from account a, company f
                            where f.company=b.company
                             and f.company_type='BIZ') where rownum<=10
So, these are two tables I am drawing data from. I also need to pull the data from the account table where there is no company information attached to it. In that case, b.company would be null and subsequently there would be no f.company or f.company_type. Any help mucho appreciated!!!!

You need to do a outer join. Like this
select a.account
     , f.company
  from account a
  left
  join company f
    on f.company= a.company
   and f.company_type = 'BIZ';
The query you have posted is incorrect. You have used an alias b in your select column but there is no such alias. Also whats the deal with ROWNUM filter?

Similar Messages

  • BDC select query with addition based on all If conditions

    Hi can any one send me the select query with conditions like
    If Itab is not initial.
    Endif. and if possible with valiadations messages also.
    IF CHECK_NUMBER of CHECK_ADVICE of the flat file = PAYR-CHECT. Then update SAP field BSEG-XREF2 .
    9.     When Flat file check Number = PAYR-CHECT then Insert or Update Flat file RECEIPT_DATE into SAP field BSEG-XREF1.
    Please send me immediately.

    >     SELECT rsnum
    >            rspos
    >            matnr
    >            werks
    >         lgort
    >            shkzg
    >            aufnr
    >            bdmng
    >            enmng                      
    >            FROM  resb INTO  TABLE it_rsnum FOR ALL ENTRIES IN it_aufnr
    >            WHERE rsnum EQ it_aufnr-rsnum
    >            AND   xloek NE 'X'
    >            AND   postp NE 'X'
    >            AND   resbbdmng GE resbenmng.
    >   ENDIF.
    >
    > Database Table RESB: 40,000,000 Records (40 Million)
    > Internal Table   it_aufnr:  20,000 Entries
    > Entries selected from RESB: 150,000.
    >
    Hi,
    the problem is the big for all entries table.
    Your 20.000 records FAE will be split into SEVERAL sql statements depending on the size of the table.
    Where do you get the it_auftrn from?
    If it's another transparent table try to JOIN this table to your big table.
    SELECT rsnum
                rspos
                matnr
                werks
            lgort
                shkzg
                aufnr
                bdmng
                enmng                      
                FROM  resb JOIN tab_auftrn  on  resbrsnum = tab_auftrnauftrn
                AND   xloek NE 'X'
                AND   postp NE 'X'
                AND   resbbdmng GE resbenmng.
    Make sure that your WHERE filter and the JOIN keys on both tables are supported by indexes.
    150.000 records about of 40 Mio. can definitly be serviced by an appropriate index:
    i.e. Index fields (check your PK or secondary indexes):
    rsnum
    enmng                      
    aufnr
    bye
    yk

  • Query with a condition - Overall results row displays incorrect value

    Hi All,
    I have a bw query with top 40 conditions. However, The Overall Result Row Figures Do Not Equal The Sum of the Column Rows.
    Although the top condition is activated, the overall result still displays the overall result of the whole report.
    I have 3 columns in the report
    Selected Period
    Prior Period and
    Variance
    The formula for variance is (Selected Period/Prior Period)-1.
    Does anyone have an idea to fix this?
    Thank you so much in advance.
    Have a great day!

    Hi Gaurav,
    Thank you so much for your reply, however this does not solve fully the issue.
    Changing the properties to "Summation" will indeed provide me with the correct sum for the "selected period" and "Prior Period." However what I need in the Overall Result Row for the "Variance" column is not the total but instead the value when the total of Selected Period is divided by Prior Period then minus 1.
    Overall Variance = (Overall Selected Period/Overall Prior Period)-1
    Do you know a way to make this possible.
    Thank you so much.

  • Query with a condition - Overall results row is wrong

    Hello,
    I have a query that uses a condition.  The query gives me the top 10 brands according to the Net Sales.  The query itself runs fine.  I just noticed however that the Overall Result row isn't giving me the correct number.
    For example:
    <b>BRAND            NETSALES    MARGIN %</b>
    Brand1           $100        25%
    Brand2           $60         10%
    Brand3           $20         15%
    <b>OVERALL RESULT   $210        2%</b>
    As you can see it does not add up or average correctly.  This query has no macros or anything, it only uses a condition.
    Any suggestions?
    Thanks,
    Nick

    A workaround I have found is the manual directions in this OSS note: 572910
    Anyone have any follow up?
    Thanks.
    Nick

  • To create query with selecting condition have AND options

    Hi All ,
    I want to create a query in SQ01 . I want to get  data from a table whose one specific field have data starting with  Z  AND  Z : * ( not OR )*  .  Is it possible to do any thing in the selection screen or i have to do any other change ?
    Please help me in this.
    Thanks & Regards ,
    Sabu.

    Hi
    Your select statment u can have
    field in ( 'Z%' , 'Z:%')
    you will get all fields starting with z and Z;
    regards

  • SQL query with multiple condition

    Below is the sample table
    ID     RATE     DATE     ORGAMNT     PAYAMOUNT
    1     3.45     12/23/2012     23000.45     19060.23
    2.    5.50     04/12/2013     45000.00     36000.54
    3.     6.44    04/16/200     60000.00     20000.00
    Select a table with highest rate, Orgamnt with Date closer to current date.

    with
    data_table as
    (select 11186 hnum,11607400 oma,to_date('2/1/2006','mm/dd/yyyy') fpay,5.51 irate,10580934.67 apb,'WELLS FARGO BANK NA' hname from dual union all
    select 11188,4801800,to_date('9/1/2006','mm/dd/yyyy'),6.3,4326951.51,'PNC BANK, NATIONAL ASSOCIATION' hname from dual union all
    select 11189,1236100,to_date('8/1/2006','mm/dd/yyyy'),6.15,1147108.9,'HEARTLAND BANK' hname from dual union all
    select 11192,1578400,to_date('4/1/2007','mm/dd/yyyy'),5.82,1470926.86,'WELLS FARGO BANK NA' hname from dual union all
    select 11193,8150400,to_date('12/1/2008','mm/dd/yyyy'),6.75,7828776.28,'OPPENHEIMER MULTIFAMILY HSG' hname from dual union all
    select 11195,3898000,to_date('5/1/2009','mm/dd/yyyy'),6.5,3752154.96,'BERKADIA COMMERCIAL MORTGAGE' hname from dual union all
    select 11196,8040000,to_date('6/1/2009','mm/dd/yyyy'),7,7775734.57,'OPPENHEIMER MULTIFAMILY HSG' hname from dual union all
    select 11197,37315000,to_date('12/1/2009','mm/dd/yyyy'),5.5,35851362.87,'RED MORTGAGE CAPITAL LLC' hname from dual union all
    select 11199,3824000,to_date('2/1/2010','mm/dd/yyyy'),5.25,3673760.35,'WALKER AND DUNLOP LLC' hname from dual union all
    select 11200,26927000,to_date('7/1/2010','mm/dd/yyyy'),4.7,25186682.65,'OAK GROVE COMMERCIAL MORTGAGE' hname from dual union all
    select 11201,7208600,to_date('10/1/2010','mm/dd/yyyy'),4.59,6949026.64,'BERKADIA COMMERCIAL MORTGAGE' hname from dual union all
    select 11204,9300000,to_date('2/1/2011','mm/dd/yyyy'),3.41,8927064.51,'PNC BANK, NATIONAL ASSOCIATION' hname from dual union all
    select 11205,5200000,to_date('2/1/2011','mm/dd/yyyy'),3.56,4997518.18,'LOVE FUNDING CORPORATION' hname from dual union all
    select 11206,6800000,to_date('5/1/2011','mm/dd/yyyy'),3.88,6576635.57,'WELLS FARGO BANK NA' hname from dual union all
    select 11208,12240000,to_date('8/1/2011','mm/dd/yyyy'),3.84,11879882.17,'WELLS FARGO BANK NA' hname from dual union all
    select 11209,12911500,to_date('10/1/2011','mm/dd/yyyy'),3.55,12542199.51,'M AND T REALTY CAPITAL CORP' hname from dual union all
    select 11210,9596900,to_date('7/1/2011','mm/dd/yyyy'),5.38,9323421.23,'LANCASTER POLLARD MORTGAGE' hname from dual union all
    select 11211,19951600,to_date('9/1/2011','mm/dd/yyyy'),3.88,19393524.45,'DEUTSCHE BANK BERKSHIRE MORTGAGE' hname from dual union all
    select 11183,4230000,to_date('4/1/2009','mm/dd/yyyy'),6.55,4069938.75,'BERKADIA COMMERCIAL MORTGAGE' hname from dual union all
    select 11212,50475000,to_date('1/1/2013','mm/dd/yyyy'),2.37,49852632.51,'LOVE FUNDING CORPORATION' hname from dual union all
    select 11213,5496000,to_date('5/1/2012','mm/dd/yyyy'),3.1,5377541.15,'WELLS FARGO BANK NA' hname from dual
    select hnum,oma,fpay,irate,apb,hname,r_oma,r_irate,r_fpay,0.5 * r_oma + 0.3 * r_irate + 0.2 * r_fpay r
      from (select hnum,oma,fpay,irate,apb,hname,
                   dense_rank() over (order by oma desc) r_oma,
                   dense_rank() over (order by irate desc) r_irate,
                   dense_rank() over (order by (sysdate - fpay)) r_fpay
              from data_table
    order by r
    HNUM
    OMA
    FPAY
    IRATE
    APB
    HNAME
    R_OMA
    R_IRATE
    R_FPAY
    R
    11197
    37315000
    12/01/2009
    5.5
    35851362.87
    RED MORTGAGE CAPITAL LLC
    2
    9
    12
    6.1
    11212
    50475000
    01/01/2013
    2.37
    49852632.51
    LOVE FUNDING CORPORATION
    1
    20
    1
    6.7
    11211
    19951600
    09/01/2011
    3.88
    19393524.45
    DEUTSCHE BANK BERKSHIRE MORTGAGE
    4
    14
    4
    7
    11200
    26927000
    07/01/2010
    4.7
    25186682.65
    OAK GROVE COMMERCIAL MORTGAGE
    3
    12
    10
    7.1
    11209
    12911500
    10/01/2011
    3.55
    12542199.51
    M AND T REALTY CAPITAL CORP
    5
    17
    3
    8.2
    11210
    9596900
    07/01/2011
    5.38
    9323421.23
    LANCASTER POLLARD MORTGAGE
    8
    10
    6
    8.2
    11196
    8040000
    06/01/2009
    7
    7775734.57
    OPPENHEIMER MULTIFAMILY HSG
    11
    1
    13
    8.4
    11208
    12240000
    08/01/2011
    3.84
    11879882.17
    WELLS FARGO BANK NA
    6
    15
    5
    8.5
    11193
    8150400
    12/01/2008
    6.75
    7828776.28
    OPPENHEIMER MULTIFAMILY HSG
    10
    2
    16
    8.8
    11186
    11607400
    02/01/2006
    5.51
    10580934.67
    WELLS FARGO BANK NA
    7
    8
    20
    9.9
    11204
    9300000
    02/01/2011
    3.41
    8927064.51
    PNC BANK, NATIONAL ASSOCIATION
    9
    18
    8
    11.5
    11201
    7208600
    10/01/2010
    4.59
    6949026.64
    BERKADIA COMMERCIAL MORTGAGE
    12
    13
    9
    11.7
    11206
    6800000
    05/01/2011
    3.88
    6576635.57
    WELLS FARGO BANK NA
    13
    14
    7
    12.1
    11183
    4230000
    04/01/2009
    6.55
    4069938.75
    BERKADIA COMMERCIAL MORTGAGE
    17
    3
    15
    12.4
    11195
    3898000
    05/01/2009
    6.5
    3752154.96
    BERKADIA COMMERCIAL MORTGAGE
    18
    4
    14
    13
    11188
    4801800
    09/01/2006
    6.3
    4326951.51
    PNC BANK, NATIONAL ASSOCIATION
    16
    5
    18
    13.1
    11213
    5496000
    05/01/2012
    3.1
    5377541.15
    WELLS FARGO BANK NA
    14
    19
    2
    13.1
    11205
    5200000
    02/01/2011
    3.56
    4997518.18
    LOVE FUNDING CORPORATION
    15
    16
    8
    13.9
    11199
    3824000
    02/01/2010
    5.25
    3673760.35
    WALKER AND DUNLOP LLC

  • CAML Query with 10 AND conditions

    Hello,
    I need some help with a CAML query. This particular query needs to have 10 AND conditions. Quite frankly, with all the nesting it is driving me a little nuts:
    What I have is:
    <Query>
    <Where>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <Eq><FieldRef Name='Column1' LookupId='TRUE' /><Value Type='Text'>10341</Value></Eq>
    <Eq><FieldRef Name='Column2' LookupId='TRUE' /><Value Type='Text'>9539</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column3' LookupId='TRUE' /><Value Type='Text'>183</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column4' LookupId='TRUE' /><Value Type='Text'>35</Value></Eq>
    </And>
    <IsNull><FieldRef Name='Column5' /></IsNull>
    </And>
    <Eq><FieldRef Name='Column6' LookupId='TRUE' /><Value Type='Text'>4387</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column7' LookupId='TRUE' /><Value Type='Text'>4204</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column8' LookupId='TRUE' /><Value Type='Text'>36</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column9' LookupId='TRUE' /><Value Type='Text'>213</Value></Eq>
    </And>
    <IsNull><FieldRef Name='Column10' /></IsNull>
    </And>
    </Where>
    </Query>
    I have added this into my ItemAdding Event Receiver as it will basically do a check for duplicate items based on the 10 columns. 
    If anyone can help guide me in this, it would be much appreciated. I have been using a CAML Query Builder to help.

    http://webcache.googleusercontent.com/search?q=cache:xji7jOxa5_EJ:aasai-sharepoint.blogspot.com/2013/02/caml-query-with-multiple-conditions.html+&cd=3&hl=en&ct=clnk&gl=in
    http://stackoverflow.com/questions/6203821/caml-query-with-nested-ands-and-ors-for-multiple-fields
    Since you are not allowed to put more than two conditions in one condition group (And | Or) you have to create an extra nested group (MSDN). The expression
    A AND B AND C looks like this:
    <And>
    A
    <And>
    B
    C
    </And>
    </And>
    Your SQL like sample translated to CAML (hopefully with matching XML tags ;) ):
    <Where>
    <And>
    <Or>
    <Eq>
    <FieldRef Name='FirstName' />
    <Value Type='Text'>John</Value>
    </Eq>
    <Or>
    <Eq>
    <FieldRef Name='LastName' />
    <Value Type='Text'>John</Value>
    </Eq>
    <Eq>
    <FieldRef Name='Profile' />
    <Value Type='Text'>John</Value>
    </Eq>
    </Or>
    </Or>
    <And>
    <Or>
    <Eq>
    <FieldRef Name='FirstName' />
    <Value Type='Text'>Doe</Value>
    </Eq>
    <Or>
    <Eq>
    <FieldRef Name='LastName' />
    <Value Type='Text'>Doe</Value>
    </Eq>
    <Eq>
    <FieldRef Name='Profile' />
    <Value Type='Text'>Doe</Value>
    </Eq>
    </Or>
    If this helped you resolve your issue, please mark it Answered

  • Sap query and additional fields.

    Hello guys.
    ABAP it's not my strong skill, but i need to develop some report.
    What i need:
    input: material, SLED, plant
    output: material, SLED, plant, values from characteristic field.
    I have created sap query with additional field type c.
    Below my code:
    TYPES: BEGIN OF charast,
            ATNAM(50)    TYPE c,
            ATWTB(8)     TYPE n,
            X(50)        TYPE n,
            C(50)        TYPE n,
            ATINN(50)    TYPE n,
            END OF charast.
    DATA: char TYPE TABLE OF charast WITH HEADER LINE.
    CALL FUNCTION 'VB_BATCH_GET_DETAIL'
       EXPORTING
         MATNR              = MCH1-MATNR
         CHARG              = MCH1-CHARG
         GET_CLASSIFICATION = 'X'
       TABLES
         CHAR_OF_BATCH      = char.
    LOOP AT char into TEST (This is an additional field type C.
       ENDLOOP.
    Questions:
    1. How i can return internal table into standard abap type, because i can create additional field only with standart types.
    2. Need i fetch exporting parameters before calling FM? Or sap query do it automatically, based on given values on selection screen of the report?
    3. How i can return only needed field from FM output? Now, when i'm executing FM via SE37 it's show desired result, but when i'm getting it from code i see strange values.
    4. If i don't know exactly return by an FM values, how i can fill structure dynamically?
    5. How i can return result of a program not only to additional field but to layout?
    Sorry for noob questions and thank you in advance guys!

    Well, seems like it work fine for me.
    Below my crappy, but working code:
    DATA: material TYPE MCHB-MATNR,
           batch    TYPE MCHB-CHARG,
           plant    TYPE MCHB-WERKS,
           sloc     TYPE MCHB-LGORT,
           gtdt     TYPE STANDARD TABLE OF clbatch,
           gtdit    TYPE clbatch.
    SELECT MATNR INTO material FROM MCHB
       WHERE MATNR = MCHB-MATNR.
    ENDSELECT.
    SELECT CHARG INTO batch FROM MCHB
       WHERE CHARG = MCHB-CHARG.
    ENDSELECT.
    SELECT WERKS INTO plant FROM MCHB
       WHERE WERKS = MCHB-WERKS.
    ENDSELECT.
    SELECT LGORT INTO sloc FROM MCHB
       WHERE LGORT = MCHB-LGORT.
    ENDSELECT.
    CALL FUNCTION 'VB_BATCH_GET_DETAIL'
       EXPORTING
         MATNR = material
         CHARG = batch
         WERKS = plant
         GET_CLASSIFICATION = 'X'
        TABLES
          CHAR_OF_BATCH = gtdt.
    READ TABLE gtdt INTO gtdit
       WITH KEY atnam = 'BATCH_SHELF_LIFE_EXPIRY_DATE'.
    GTD = gtdit-ATWTB.

  • SQ02 - Query with adicional fields

    Hi, I need your help to develop a query with additional fields.
    The case is that:
    In my query I only have a table VBAK and my propose is that this query returns me the quantity that are in a sales document for some material that should be selection parameters.
    So I create 2 additional fields: one that is the u2018 Material u2018 that have no codification and other that is the quantity that have the code:
    select single ZMENG into quantity from VBAK where matnr = material.
    But the result is null, I don't know why.
    Can you help me?
    Thanks in advance.
    Dora

    Hi,
    MATNR is not available in VBAK !
    You have to create first an info-set using SQ02 : here you link VBAK and VBAP, and select the fields you need.
    From SQ01, create a new query where matnr is a selection field ....

  • Query with progressive code

    Hi,
    I've this table:
    COD_ID.....................DESC_COD
    MT001......................PAL
    MT001......................PAL
    NS007......................PAL
    NS007......................TRA
    NM332......................RIP
    NM332......................RIP
    NM332......................RIP
    NM332......................RIP
    NB112......................RIP
    VT774......................PAL
    VT774......................RIP
    VT774......................PAL
    NT999......................PAL
    ............................. --other 1000 records
    I'd like to write one query with this condition:
    If DESC_COD = PAL I must add at the column COD_ID "-Pn" with n = 0 to 99
    If DESC_COD = TRA I must add at the column COD_ID "-Tn" with n = 0 to 99
    If DESC_COD = RIP I must add at the column COD_ID "-Rn" with n = 0 to 99
    If DESC_COD = PAL and COD_ID has 3 same values I'll get COD_ID-P01, COD_ID-P02, COD_ID-P03
    If DESC_COD = RIP and COD_ID has 5 same values I'll get COD_ID-R01, COD_ID-R02, COD_ID-R03, COD_ID-R04, COD_ID-R05
    In my case I'd like this output:
    COD_ID.....................DESC_COD
    MT001-P01..................PAL
    MT001-P02..................PAL
    NS007-P01..................PAL
    NS007-R01..................TRA
    NM332-R01..................RIP
    NM332-R02..................RIP
    NM332-R03..................RIP
    NM332-R04..................RIP
    NB112-R01..................RIP
    VT774-P01..................PAL
    VT774-R01..................RIP
    VT774-P02..................PAL
    NT999-P01..................PAL
    ............................. --other 1000 records
    Thank in advance!

    It's always good to test it ...
    SQL> create table mytable (cod_id,desc_cod)
      2  as
      3  select 'MT001', 'PAL' from dual union all
      4  select 'MT001', 'PAL' from dual union all
      5  select 'NS007', 'PAL' from dual union all
      6  select 'NS007', 'TRA' from dual union all
      7  select 'NM332', 'RIP' from dual union all
      8  select 'NM332', 'RIP' from dual union all
      9  select 'NM332', 'RIP' from dual union all
    10  select 'NM332', 'RIP' from dual union all
    11  select 'NB112', 'RIP' from dual union all
    12  select 'VT774', 'PAL' from dual union all
    13  select 'VT774', 'RIP' from dual union all
    14  select 'VT774', 'PAL' from dual union all
    15  select 'NT999', 'PAL' from dual
    16  /
    Tabel is aangemaakt.
    SQL> select /* Aalap Sharma */ cod_id||'-'||rn, desc_cod
      2  from
      3   (
      4     select
      5       cod_id, desc_cod,
      6       row_number() over(partition by cod_id order by cod_id) rn
      7     from mytable
      8  )
      9  /
    COD_ID||'-'||RN                                DES
    MT001-1                                        PAL
    MT001-2                                        PAL
    NB112-1                                        RIP
    NM332-1                                        RIP
    NM332-2                                        RIP
    NM332-3                                        RIP
    NM332-4                                        RIP
    NS007-1                                        PAL
    NS007-2                                        TRA
    NT999-1                                        PAL
    VT774-1                                        PAL
    VT774-2                                        RIP
    VT774-3                                        PAL
    13 rijen zijn geselecteerd.
    SQL> select cod_id || '-' || substr(desc_cod,1,1) ||
      2         to_char(row_number() over (partition by cod_id,desc_cod order by null),'fm00') cod_id
      3       , desc_cod
      4    from mytable
      5  /
    COD_ID     DES
    MT001-P01  PAL
    MT001-P02  PAL
    NB112-R01  RIP
    NM332-R01  RIP
    NM332-R02  RIP
    NM332-R03  RIP
    NM332-R04  RIP
    NS007-P01  PAL
    NS007-T01  TRA
    NT999-P01  PAL
    VT774-P01  PAL
    VT774-P02  PAL
    VT774-R01  RIP
    13 rijen zijn geselecteerd.Regards,
    Rob.

  • Query with Top N Condition (Result Row)

    Hi,
    I made a query with an active top n condition. The query has 2 Keyfigures and 1 formula
    Gross-sales acutal | Gross-sales previous year | Previous Year %
    So that to result line is correct, I had to say "Calculate result as summation" for the keyfigures
    gross sales actual and gross sales previous year. That works.
    I have the problem with my formula. the formular for previous year % is defined as follows:
    gross sales actual %A gross sales previous year
    Example Top 3 Customer
                        gross sales actual          gross sales prev. year         prev. year %
    Cust 1          100                                   80                                       125 %
    Cust 2          90                                     45                                        200 %
    Cust 3           80                                    60                                        133 %
    Result          270                                   185                                       142.8 % ( 350 * 100 / 245 )
    The result of 142 % is the correct result without the condition top 3. with the top 3 condition
    the result should be 270 * 100 / 185 = 145.9 %
    Additional customer without top 3 condition
    Cust 4          50                                       40                                        125 %
    Cust 5          30                                        20                                        150 %
    It shows the correct result for each single line. The result in the result row is wrong. it is calculated
    without taking the active condition. the formular calculates
    with the total gross sales actual and the total of gross sales prev. year.
    is there any solution the achieve the correct % in the result row?
    thanks for your help.
    Pascal

    Pascal,this is a known behavior with conditions.When you apply condition it just hide the extra rows and it does not impact the result row.So your result row actually shows the value irrespective of the condition you apply.
    Now with the help of local functions like calculate result as summation you can show the correct sum after applying the condition but when you try to use that result in some calculation then it takes the original value thereby discarding the calculated value.
    Same is happening in your case as well.Its taking the original value i.e 350 and not the calculated sum after condition i.e 270.
    Hope this helps.
    Regards,
    AL

  • Query combining spatial condition with regular condition works very slow

    I had a query like the following. The first part of the condition is a sdo_relate, and others are just regular conditions. If I execute the query with those two condiction separately, they both works very fast, but I combine them together, it's terriblely slow(more than 5 minutes) I tried different combination, and try the /* ordered*/ hint too. Still does not work. Any oracle pro got an idea to optimize the query? Thanks a lot!
    select * from MM_ACCOUNT
    where SDO_RELATE(GEOLOC,
         (SELECT SDO_AGGR_UNION(MDSYS.SDOAGGRTYPE(geoloc, 5))
         from MM_METRO_FBR_BF
         where ID = 'cyecroi0o1'
         and CREATION_TIME='1026758969052')
         ,'mask=inside querytype=window') = 'TRUE'
    and VERTICAL_MKT_SUB_GRP_SIC in ('Retail','Air','Ground','Other','Water','Advertising','Entertainment/Recreation','Other (broadcast etc)','Publishing','Sports / Sports Club''s') and ENTERPRISE_CODE in ('Medium-Large','Medium-Small')
    Tim

    Hi, Daniel
    After I drop the indexes for vertical market, and tried this query you suggested eariler:
    select /*+ ordered */ * from
    (select /*+ no_merge */
    SDO_AGGR_UNION(MDSYS.SDOAGGRTYPE(geoloc, 5)) bufferShape
    from MM_METRO_FBR_BF
    where ID = 'cyecroi0o1'
    and CREATION_TIME='1026758969052') aggr_geom,
    MM_ACCOUNT
    where SDO_RELATE(GEOLOC, aggr_geom.bufferShape,
    'mask=inside querytype=window') = 'TRUE'
    and VERTICAL_MKT_SUB_GRP_SIC in ('Retail--Retail','Air--Transportation','Ground--Transportation','Other--Transportation','Water--Transportation','Advertising--Media / Entertainment','Entertainment/Recreation--Media / Entertainment','Other (broadcast etc)--Media / Entertainment','Publishing--Media / Entertainment') and ENTERPRISE_CODE in ('Medium-Large','Medium-Small')
    IT DID work significantly faster!!!! Thanks a lot! HOwever, I'm just a little bit confused here, why the index is actually slowing things down instead of making it faster?? And what's the "no_merge" doing here?
    Thanks for you great help again!
    Tim

  • Dynamic select query with dynamic where condition

    Hi all,
    I want to use the dynamic select query with dynamic where condition. For that I used the below code but I am getting dump when using this code.
    Please advice, if there is any other way to achieve this requirement.
    Thanks,
    Sanket Sethi
    Code***************
    PARAMETERS: p_tabnam      TYPE tabname,
                p_selfl1      TYPE edpline,
                p_value       TYPE edpline,
                p_where1      TYPE edpline .
    DATA: lt_where    TYPE TABLE OF edpline,
          lt_sel_list TYPE TABLE OF edpline,
          l_wa_name   TYPE string,
          ls_where    TYPE edpline,
          l_having    TYPE string,
          dref        TYPE REF TO data,
          itab_type   TYPE REF TO cl_abap_tabledescr,
          struct_type TYPE REF TO cl_abap_structdescr,
          elem_type   TYPE REF TO cl_abap_elemdescr,
          comp_tab    TYPE cl_abap_structdescr=>component_table,
          comp_fld    TYPE cl_abap_structdescr=>component.
    TYPES: f_count TYPE i.
    FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
    *                <ls_outtab> TYPE ANY,
                    <l_fld> TYPE ANY.
    struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
    elem_type   ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
    comp_tab = struct_type->get_components( ).
    comp_fld-name = 'F_COUNT'.
    comp_fld-type = elem_type.
    APPEND comp_fld TO comp_tab.
    struct_type = cl_abap_structdescr=>create( comp_tab ).
    itab_type   = cl_abap_tabledescr=>create( struct_type ).
    l_wa_name = 'l_WA'.
    CREATE DATA dref TYPE HANDLE itab_type.
    ASSIGN dref->* TO <lt_outtab>.
    *CREATE DATA dref TYPE HANDLE struct_type.
    *ASSIGN dref->* TO <ls_outtab>.
    * Creation of the selection fields
    APPEND p_selfl1 TO lt_sel_list.
    APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
    ** Creation of the "where" clause
    *CONCATENATE p_selfl1 '= '' p_value ''.'
    *            INTO ls_where
    *            SEPARATED BY space.
    *APPEND ls_where TO lt_where.
    * Creation of the "where" clause
    APPEND p_where1 TO lt_where.
    * Creation of the "having" clause
    l_having = 'count(*) >= 1'.
    * THE dynamic select
    SELECT          (lt_sel_list)
           FROM     (p_tabnam)
           INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>.
    *       WHERE    (lt_where).

    Hi Sanket,
    The above given logic of mine works for you, put the code in the If condition and try-
    just like below:
    IF NOT P_EBELN IS INITIAL.
    lt_where = '& = ''&'' '.
    REPLACE '&' WITH p_ebeln INTO lt_where.
    REPLACE '&' WITH field_value INTO lt_where.
    SELECT (lt_sel_list) INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
    FROM (p_tabnam)
    WHERE (lt_where).
    ENDIF.
    thanks\
    Mahesh

  • Sql query with conditions and calculations???

    Hi,
    how I can build a query with conditions and calculations?
    E.g. I've got this table
    Start          | End     |     Working Place     |     Mandatory
    01-JAN-13 | 11-JAN-13 |     Office           |          1
    14-JAN-13 | 25-JAN-13 |     Home Office      |     0
    04-MRZ-13| 15-MRZ-13 |     Office           |          0
    11-FEB-13 | 22-FEB-13 |     Office           |          1
    Now if column working place=Office and column mandatory=0
    the new column "price" has to calculate: (End-Start)* $25.00
    and if working place=Office and column mandatory=1
    the "price" column has to calculate: (End-Start)* $20.60
    else $0.00
    I tried it with the case statement but I didn't know how
    to calculate my values and display it to the virtual column "price".
    Something like
    case
    when Working_Place = 'Office' and Mandatory=1
         then ...
    else '0.00'
    end as PRICE
    Or is it not possible?
    Edited by: DB2000 on 12.03.2013 05:09

    Use CASE:
    select  start_dt,
            end_dt,
            working_place,
            mandatory,
            case
              when working_place = 'Office' and mandatory = 0 then (end_dt - start_dt) * 25
              when working_place = 'Office' and mandatory = 1 then (end_dt - start_dt) * 20.60
              else 0
            end price
      from  tbl
    START_DT  END_DT    WORKING_PLA  MANDATORY      PRICE
    01-JAN-13 11-JAN-13 Office               1        206
    14-JAN-13 25-JAN-13 Home Office          0          0
    04-MAR-13 15-MAR-13 Office               0        275
    11-FEB-13 22-FEB-13 Office               1      226.6
    SQL> SY.

  • Performance of APD with source as 'Query with conditions'

    Hi,
    I have a question regarding the performance of an APD query with conditions when it is run in the background.
    I have an infocube with 80 million records.I have a query to find Top 15 (Condition In query) Customers per territory.
    With the help of an APD Query (Source) i wanted to populate the details (customer category , etc) of the Top 15 Customers into a DSO (Target)
    Right now it takes 6 minutes to run the query in web.
    I wanted to know how feasible it is to use an APD (run in backgrnd) to dump the results of the BEx query (which has conditions Top 15) into DSO.
    Also , what other options do i have ?
    Appreciate your answers.
    Regards

    Thomas thanks for the response.  I have checked the file on the app server and found that the lines with more than 512 characters are being truncated after 512 characters.  Basis team is not aware of any such limits on the app server.  I am sure few on the forum would have extracted data to a file on the application server using APD.  Please note that the file extraction to the client workstation is working as expected (posts lines more than 512 characters).

Maybe you are looking for

  • Mail unexpectedly quits when connecting wifi

    This is just ONE of the issues I am having with the Mail application: I would say that 80% of the time I reconnect to a wifi network, Mail will quit 'unexpectedly' I also have issues with mail folders not displaying contents until I have a connection

  • How to restrict the user to enter the item in purchase order?

    I want to restrict user to enter the item in purchase order. How can i do this? Please help Abhishek

  • Document text blurry

    Hi, i have two word documents, one looks blurry and washed out, the other one is crystal clear. Any idea? both are arial 11pt Both pdf are created from a word 2010 documents with the same settings from within acrobat the view settings in acrobat are

  • How to connect Forms 6i with MS Access

    Dear All: Can we connect Forms 6i with MS Access? If yes then how? Any document? Any suggestions? Thanks Hassan

  • Windows XP SP3 PDF Printing Problems

    Hi! i saw that there are some topics about problems with network printer after installing sp3 I have installed SP3 an the latest version of acrobat reader (yesterday) and have the same problem. Everytime i try to print, it says that there is no print