Inner Join with Negative Condition

Hi Gurus,
I have to select data from two table and I have to exclude some records based on user selection
I am slecting data fromm MARC and MVKE and I have provided two select option for MTPOS from MVKE  and EKGRP from MARC
Exclude the entries where both the field values match with an AND condition
  i.e  MVKEMTPOS = XXXX AND MARCEKGRP = YYYY
Can I write the below statement
  Select  . ....
                 JOIN ......
                WHERE  ( MVKE~MTPOS  NOT IN S_MTPOS AND
                                 MARC~EKGRP NOT IN  S_EKGRP )

A where clause on joined tables should work as a Open SQL does on a table read.  In other words, if you have a select-options entry on the screen, and the user chose to OMIT a range (Exclude Between low high), I would expect to get the correct results with...
where..... IN selection-option range.
I would not, however, write a NOT IN select-option, though....the user would have already determined that with his Exclude choice, but it will be a lengthy data retrieval (full table scans).
On the other hand, if you expecting the user to say I-include between low and high as a range that is to be excluded then you can do your way, which should result in a full table scan on both tables, or you can retrieve the remainder of the where clause and the do a 2nd step to delete from your internal table where the values equal those to be omitted.
Is there any way you can convert this to include...such as looking up possible values, building a ranges table with Include where equal to a single value, then delete the entries that should be omitted from that ranges table....then it becomes
where field in my_ranges_table....a much faster retrieval.

Similar Messages

  • Replacing a inner join with for all entries

    Hi Team,
       In a already developed program I am replacing a inner join with select query follow up with for-all-entris and passing the data to final internal table but in both the case the result should be same then only my replacement will be correct. But my no records in both cases differs. This happening because when i am selecting data from first data base table is 32 lines. then I am doing fo-all-entries moving all the duplicate entries then the no records are four. but in final internal table i am looping the first internal table. So in final internal table the no of records are 32. But in inner join query the records are 16.So please let me know how resolve this issue?
    Thanks and REgards
    Deepa

    Hi Thomas,
      Thanks for ur suggestion.
    The solved that in below.
    In select query I did not change anything The way I had written the code was correct.
    I think many of us know how to write that how to make the performance better in that way.
    I made the change when I transfered the to final internal table.
    The original Inner join code:
    select a~field1 a~field2 a~field3 b~field2 b~field3 b~field4
               from dbtab1 as a  inner join dbtab2 as b
              on a~field1 = b~field1 into it_final where
              a~field1 in s_field1. [Field1  in both the table are key field]
    Before code:
    Sort itab1 by key-fields.
    sort itab2 by keyfields.
    loop at itab1 into wa1.
    move: wa1-field1 to wa_final-field1,
               wa1-field2 to wa_final-field2,
               wa1-field3 to wa_final-field3.
    read table itab2 into wa2 witk key field1 = wa1-field1 binary search.
      if sy-subrc = 0.
      move : wa2-field2 to wa_final-field4,
                 wa2-field3 to wa_final-field5,
                 wa2-field4 to wa_final-field6.
    append wa_final to it_final.
    endif.
    Clear : wa1, wa2, wa_final.
    endloop.
    In this case if the one key fieild value is not present there in second internal table but its there in first internal table still it will read that row with 2nd internal values having zeroes. Normally what does not happen in inner join case if the key field value will same in both the case ,then that will fetch only those rows.
    Changed Code
    loop at itab1 into wa1.
    read table itab2 into wa2 witk key field1 = wa1-field1 binary search.
      if sy-subrc = 0.
    move: wa1-field1 to wa_final-field1,
               wa1-field2 to wa_final-field2,
               wa1-field3 to wa_final-field3.
      move : wa2-field2 to wa_final-field4,
                 wa2-field3 to wa_final-field5,
                 wa2-field4 to wa_final-field6.
    append wa_final to it_final.
    endif.
    Clear : wa1, wa2, wa_final.
    endloop.
    In this case the values will read to final internal table if both key field matches.
    With Regards
    Deepa

  • INNER JOIN with FOR ALL ENTRIES IN Performance ?

    I am using following the following <b>Select using Inner join with For All Entries in.</b>
          SELECT kebeln kebelp kvbeln kvbelp
            FROM ekkn AS k INNER JOIN ekbe AS b ON kebeln = bebeln
                                               AND kebelp = bebelp
            INTO TABLE gi_purchase
             FOR ALL ENTRIES
             IN gi_sales
          WHERE k~mandt EQ sy-mandt
            AND k~vbeln EQ gi_sales-vbeln
            AND k~vbelp EQ gi_sales-posnr
            AND b~budat EQ p_date.
    If i am not doing inner join then I will have to do 2 select with for all entries in on ekkn and ekbe tables and then compare them.
    <b>I want to know which one has better performance
    Inner join with for all entries in
                    or
    2 Selects with for all entries in</b>

    the join is almost aways faster:
    <a href="/people/rob.burbank/blog/2007/03/19/joins-vs-for-all-entries--which-performs-better">JOINS vs. FOR ALL ENTRIES - Which Performs Better?</a>
    <a href="http://blogs.ittoolbox.com/sap/db2/archives/for-all-entries-vs-db2-join-8912">FOR ALL ENTRIES vs DB2 JOIN</a>
    Rob

  • Inner Join with For All Entries - Performance ?

    I am using following the following <b>Select using Inner join with For All Entries in.</b>
          SELECT kebeln kebelp kvbeln kvbelp
            FROM ekkn AS k INNER JOIN ekbe AS b ON kebeln = bebeln
                                               AND kebelp = bebelp
            INTO TABLE gi_purchase
             FOR ALL ENTRIES
             IN gi_sales
          WHERE k~mandt EQ sy-mandt
            AND k~vbeln EQ gi_sales-vbeln
            AND k~vbelp EQ gi_sales-posnr
            AND b~budat EQ p_date.
    If i am not doing inner join then I will have to do 2 select with for all entries in on ekkn and ekbe tables and then compare them.
    <b>I want to know which one has better performance
    Inner join with for all entries in
                    or
    2 Selects with for all entries in</b><b></b>

    An Inner Join with for all entries should be done if you add this....
    IF NOT gi_sales[] IS INITIAL.
    SELECT k~ebeln k~ebelp k~vbeln k~vbelp
    FROM ekkn AS k INNER JOIN ekbe AS b ON k~ebeln = b~ebeln
    AND k~ebelp = b~ebelp
    INTO TABLE gi_purchase
    FOR ALL ENTRIES
    IN gi_sales
    WHERE k~mandt EQ sy-mandt
    AND k~vbeln EQ gi_sales-vbeln
    AND k~vbelp EQ gi_sales-posnr
    AND b~budat EQ p_date.
    ENDIF.
    Also, while you use an index or the complete key for the SELECT, your not going to suffer from lack of performance -;)
    Greetings,
    Blag.

  • Coupling  INNER  JOIN   with   FOR  ALL  ENTRIES  statement

    Hi  All,
         I   am  coupling   INNER  JOIN  with  FOR  ALL  ENTRIES  statement  .....
         Would   you  please  highlight  its  implications ??   Is  it  a  best  practise ? 
         Is  it  advicable  to  use  MULTIPLE   INNER  JOINs  with  a  FOR  ALL  ENTRIES ???
        SORT itab BY matnr.
        IF NOT itab[] IS INITIAL.
          SELECT       epmatnr epebeln ep~ebelp
                       epwerks epmenge ep~netpr
                       ekps_psp_pnr ebbelnr eb~menge
                       INTO TABLE iekpo
                       FROM ekpo AS ep
                       INNER JOIN ekkn AS ek
                       ON  ekebeln = epebeln
                       AND ekebelp = epebelp
                       INNER JOIN ekbe AS eb
                       ON     ebebeln = epebeln
                       AND    ebebelp = epebelp
                       AND    eb~bwart = '101'
                       FOR ALL  ENTRIES IN itab
                       WHERE   ep~matnr = itab-matnr.
          IF sy-subrc EQ 0.
            SORT iekpo BY matnr werks.
            LOOP  AT  itab ASSIGNING  <itab>.
              READ TABLE iekpo WITH KEY matnr = <itab>-matnr
                                        werks = <itab>-werks
                                        BINARY SEARCH.
              IF sy-subrc EQ 0.
                MOVE iekpo-matnr      TO   itab1-matnr.
                MOVE iekpo-ebeln      TO   itab1-ebeln.
                MOVE iekpo-ebelp      TO   itab1-ebelp.
                MOVE iekpo-netpr      TO   itab1-poprice.
                MOVE iekpo-werks      TO   itab1-werks.
                MOVE iekpo-menge      TO   itab1-menge1.
                MOVE iekpo-menge1     TO   itab1-menge2.
                MOVE iekpo-belnr      TO   itab1-belnr.
                MOVE iekpo-ps_psp_pnr TO   itab1-pspel.
                MOVE <itab>-pspel     TO   itab1-tpspel.
                MOVE <itab>-sobkz     TO   itab1-sobkz.
                MOVE <itab>-fo_qty    TO   itab1-fo_qty.
                MOVE <itab>-schgt     TO   itab1-schgt.
                MOVE <itab>-postp     TO   itab1-postp.
                MOVE <itab>-beskz     TO   itab1-beskz.
                pend_qty = iekpo-menge1 - iekpo-menge2.
                MOVE pend_qty         TO   itab1-pending.
                APPEND itab1.
                pend_qty = 0.
              ENDIF.
            ENDLOOP.
          ENDIF.
        ENDIF.
      ENDIF.
    Regards
    Jaman
    Edited by: ABAP Techie on Sep 15, 2008 12:39 PM
    Edited by: ABAP Techie on Sep 15, 2008 12:41 PM

    best practise ... don't know ... it is allowed and o.k.
    If possible you should of coourse to have no FOR ALL ENTRIES at all !
    Joins, there is no general rule, check indexes etc.
    The first SORT, I don't that it help for anything, use it together with the delete adjacent duplicates if you expect duplicates in the driver table.
    o.k., it can help, if there is a loop afterwards and an append inside, because the new table itab1 is then sorted.
    Siegfried

  • INNER join with dynamic table name ?

    Hi,
    I have a problem with this statement.
    DATA: g_dso_bic_dofr TYPE tabname.
    SELECT t1~/bic/ziparomr
           t2~/bic/zifremom
    INTO (wa_rater_paromr-/bic/ziparomr,
           wa_rater_paromr-/bic/zifremom)
    *   FROM /bic/azd0bfr5100 AS t1     "equivalent to the dynamic statement below
    " this is the  problem
        FROM (g_dso_bic_dofr )AS t1
        INNER JOIN /bic/pzifremom AS t2
          ON t1~/bic/ziparomr = t2~/bic/ziparomr
    " --- to here
        WHERE t1~/bic/zikom     =  v_kommune
    The compile check doesnt work when i use the variable table name.
    I get
    "Wrong expression "INNER" in FROM clause. WHERE condition."
    Can anyone help me.
    Br Rasmus.

    " this is the  problem
    *    FROM (g_dso_bic_dofr )AS t1   "<<--- check spaces in here
        FROM (g_dso_bic_dofr) AS t1    "<<--- and here
        INNER JOIN /bic/pzifremom AS t2
          ON t1~/bic/ziparomr = t2~/bic/ziparomr
    " --- to here
    I think there's the problem, the space behind the parenthesis.
    Regards

  • Inner join with for-all entries

    Why is the below inner join-for all entries does not result in expected output ?
    REPORT  ZTST3                                   .
    tables : ztst1,ztst2 .
    * table ztst1 has 4 fields : mandt,ebeln,ebelp,etenr,char4. ; ztst2 has
    * 3 fields : mandt,ebeln,ebelp,matnr
    *Entries in ztst1
    * EBELN       EBELP   ETERN  CHAR4
    * 5000000000  00010    0001    abc
    * 5000000000  00010    0002    cbd
    * 5000000000  00010    0003    efg
    *Entries in ztst2
    * EBELN       EBELP   matnr
    * 5000000000  00010    matabc
    *expected itab after inner join
    * EBELN       EBELP   CHAR4  MAtnr
    * 5000000000  00010   abc    matabc
    * 5000000000  00010   cbd    matabc
    * 5000000000  00010   efg    matabc
    data : begin of itab1 occurs 0,
           ebeln type ebeln,
           ebelp type ebelp,
           end of itab1.
    data : begin of itab occurs 0,
           ebeln type ebeln,
           ebelp type ebelp,
           char4 type char4,
           matnr type matnr,
           end of itab.
    start-of-selection.
    itab1-ebeln = '5000000000'.
    itab1-ebelp = '00010'.
    append itab1.
    select ztst1~ebeln
           ztst1~ebelp
           ztst1~char4
           ztst2~matnr into corresponding fields of table itab
    from ztst1 inner join ztst2
    on ztst1~ebeln = ztst2~ebeln and
       ztst1~ebeln = ztst2~ebelp
    for all entries in itab1
    where
    ztst1~ebeln eq itab1-ebeln and
    ztst1~ebelp eq itab1-ebelp .
    * why does it return no entries;
    break-point.

    For example in the bellow case
    *Entries in ztst1
    EBELN       EBELP   ETERN  CHAR4
    5000000000  00010    0001    abc
    5000000000  00010    0002    cbd
    5000000000  00010    0003    efg
    5000000002  00020    0003    efg
    5000000002  00020    0003    efg
    *Entries in ztst2
    EBELN       EBELP   matnr
    5000000000  00010    matabc
    5000000002  00020    abc
    may it will return you 2 records yes, than I think you have under stand the working of u201Cfor all entriesu201D ?
    And the following case I think it will work fine.
    *Entries in ztst1
    key  EBELN       EBELP   ETERN  CHAR4
    1       5000000000  00010    0001    abc
    2       5000000000  00010    0002    cbd
    3       5000000000  00010    0003    efg
    4       5000000002  00020    0003    efg
    5       5000000002  00020    0003    efg
    *Entries in ztst2
    EBELN       EBELP   matnr
    5000000000  00010    matabc
    5000000002  00020    abc
    select  ztst1~key
    ztst1~ebeln
           ztst1~ebelp
           ztst1~char4
           ztst2~matnr into corresponding fields of table itab
    from ztst1 inner join ztst2
    on ztst1~ebeln = ztst2~ebeln and
       ztst1~ebelp = ztst2~ebelp
    for all entries in itab1
    where
    ztst1~ebeln eq itab1-ebeln and
    ztst1~ebelp eq itab1-ebelp .
    Sorry, I donu2019t have system with me right now and I am sending you with out testing but I am sure that it is working the same way.
    Please Reply if any problem
    Kind Regards,
    Faisal

  • Outer Joins with multiple conditions - alternatives to UNION?

    It is my understanding that Oracle 8i does not directly support mutiple conditions for outer joins. For instance, I'm looking for PEOPLE who may, or may not, be on MEDICATIONS.
    All MEDICATIONS are listed with DRUGNAME and DRUGID. There thousand of different drugs. I'm only looking for PEOPLE on either one or two of them (to make it simple) or no drug at all (ignoring all other DRUGS they're on..) IF they are on the DRUG, it's gerts printed.
    I'd ideally do a LEFT OUTER JOIN to do this with multiple conditions:
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    (MEDICATION.DRUGID (+) = 632 OR
    MEDICATION.DRUGID (+) = 956)
    This, of course, is not valid, at least in 8i...
    So I've taken the UNION approach:
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    MEDICATION.DRUGID (+) = 632
    UNION
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    MEDICATION.DRUGID (+) = 956
    This of course, does work, but as I've added more drugs this becomes quite unwieldly and not really sure what this does to performance. (There are also several more joins to other tables, not relevent here.)
    In addition, if I import this into Crystal Reports 8.5 (as opposed to the Crystal Query Designer), it refuses to recognize the UNION.
    -- Any suggestions for alternative syntax ???
    -- Has this been addressed in 9i ???
    Thanks,
    Will

    You could try
    select Distinct Person.Name, Med.DrugName, Med.DrugId
    from Person,
    (select ID, DrugName, DrugId from Medication
    where DrugId in (632, 956) ) Med
    where Person.ID = Med.ID(+)
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    (MEDICATION.DRUGID (+) = 632 OR
    MEDICATION.DRUGID (+) = 956)
    This, of course, is not valid, at least in 8i...
    So I've taken the UNION approach:
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    MEDICATION.DRUGID (+) = 632
    UNION
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    MEDICATION.DRUGID (+) = 956
    This of course, does work, but as I've added more drugs this becomes quite unwieldly and not really sure what this does to performance. (There are also several more joins to other tables, not relevent here.)
    In addition, if I import this into Crystal Reports 8.5 (as opposed to the Crystal Query Designer), it refuses to recognize the UNION.
    -- Any suggestions for alternative syntax ???
    -- Has this been addressed in 9i ???
    Thanks,
    Will

  • Can we use inner joins with for all entries?

    Hi,
        Can we use innerjoin on two tables MARA and MAKT against the materials in
        the  internal table.
        If so ,please let me know whether there is performance issue.Because if there is
        bad performance issue or something else like thise means,my project manager
        wont allow to include.
        So can one let me know about this.
    Thanks,
    Balaji

    Hi Arunkumar,
                               I think you are not clear.My question is can I use innerjoin with
    for all entries.For example below is my code.
    SELECT A~MATNR
             B~MAKTX
             A~MTART
             A~MATKL
             FROM MARA AS A INNER JOIN MAKT AS B
             ON AMATNR = BMATNR
             INTO TABLE IT_MARA_MAKT
             FOR ALL ENTRIES IN IT_MATNR
             WHERE A~MATNR = IT_MATNR-MATNR
             AND   A~EXTWG = P_EXTWG
             AND   A~SPART = P_SPART.
    Can we use like this for all entries along with innerjoins.
    Thanks,
    Balaji

  • Inner join with data also from non having join column

    I have an Dim table which has to be joined with Fact Table using inner join, but also display the Dimension value " MasterGroup " inspite of data present or not in the fact table.
    My Query:  .. This is an part of my stored procedure with more tables
    SELECT a.SalesAmount, b.HeaderGroup ,c.CityName
    FROM dbo.FactItem a
    inner join dbo.[DimHeader] b
    on a.sid = b.sid
    left join dbo.DimCity c
    on a.cityid = c.id
    My DimHeader Table will have data like
    MasterGroup
    ChildGroup
    etc...
    which is an attribute.
    There might not be any relevent fact data, but still i want the dimension data to display the "MasterGroup"
    ShanmugaRaj

    hello ,
    usually this is not possible when the column you want to display when the matches not found from a table having a distinct values which are hard to declared static..
    you can incorporate something like this if you cant change the join type ..
    select distinct HeaderGroup from dbo.[DimHeader] tbl_outerleft join (SELECT a.sid,a.SalesAmount, b.HeaderGroup ,c.CityName
    FROM dbo.FactItem a
    inner join dbo.[DimHeader] b
    on a.sid = b.sid
    left join dbo.DimCity c
    on a.cityid = c.id) tbl_Main on tbl_Main.sid =tbl_outer.sid
    Dilip Patil..

  • Problem in Accession inner join with [Microsoft][SQLServer 2000 Driver

    Hi
    Can you tell me what can be cause my sql statement is correct gives result but
    if i used below statement in my JSP ,cause error
    1)
    ps1=connection.prepareStatement("select RQM_IN_RQSTN_ID_PK,RQD_IN_ITM_ID_FKPK,RQD_VC_ITM_DSCRPTN,RQD_IN_STTS_ID_FK,C.SMT_VC_STTS_NM,a.RQM_DT_PRPSD_DLVRY_DT"+
    "from PAS_RQM_RQSTN_MSTR a "+
    "inner join PAS_RQD_RQSTN_DTLS b on a.RQM_IN_RQSTN_ID_PK = b.RQD_IN_RQSTN_ID_FKPK and RQD_IN_STTS_ID_FK = 4"+
    "INNER JOIN PAS_SMT_STTS_MSTR C ON C.SMT_IN_STTS_ID_PK=B.RQD_IN_STTS_ID_FK" +
    "where a.RQM_VC_DTRTMNT_INVLV='Technology' ");
    2) Error Generate
    java.sql.SQLException
    [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect syntax near 'a'.
    What can be the cause
    Thanks

    ps1=connection.prepareStatement("select
    RQM_IN_RQSTN_ID_PK,RQD_IN_ITM_ID_FKPK,RQD_VC_ITM_DSCRP
    TN,RQD_IN_STTS_ID_FK,C.SMT_VC_STTS_NM,a.RQM_DT_PRPSD_D
    LVRY_DT"+
    "from PAS_RQM_RQSTN_MSTR a "+
    "inner join PAS_RQD_RQSTN_DTLS b on
    a.RQM_IN_RQSTN_ID_PK = b.RQD_IN_RQSTN_ID_FKPK and
    RQD_IN_STTS_ID_FK = 4"+
    "INNER JOIN PAS_SMT_STTS_MSTR C ON
    C.SMT_IN_STTS_ID_PK=B.RQD_IN_STTS_ID_FK" +
    "where a.RQM_VC_DTRTMNT_INVLV='Technology' ");This is a problem due to not providing spaces where they are needed. See the places where I have highlighted.
    A better way is to generate the String first [use StringBuffer as a good practice for appending instead of String "+"] and print it out to check if it is correct.
    ***Annie***

  • Inner join with if statement , how to combine these code ?

    Hello everyone, I have 2 group of code here. This 2 group of code is working without error. But I face a problem , I need to group up this 2 group of code. Please take a look, thank you This is the first code i create.
    SELECT r.Name , r.Restaurant_ID, f.feature, r.Price_Range, r.Cuisine_ID, c.Cuisine,
        s.State_ID, s.State, l.Location_ID, l.Area, l.State_ID, r.Name, r.Location_ID
    FROM Restaurants r, Bridge1_Restaurant_Features b, Features f, Cuisine c, State s, Location l
            where 0=0
            AND b.Feature_ID = f.Feature_ID
            AND b.Restaurant_ID = r.Restaurant_ID
            AND r.Cuisine_ID = c.Cuisine_ID
            AND r.Location_ID = l.Location_ID
            AND l.State_ID = s.State_ID
            <cfif ARGUMENTS.Feature_ID IS NOT "">
            AND b.Feature_ID IN (#ARGUMENTS.Feature_ID#)
            </cfif>
            <cfif ARGUMENTS.Price_Range IS NOT "">
            AND r.Price_Range IN (#ARGUMENTS.Price_Range#)
            </cfif>
            <cfif ARGUMENTS.Cuisine IS NOT "">
            AND r.Cuisine_ID = (#ARGUMENTS.Cuisine#)
            </cfif>
            <cfif val(ARGUMENTS.LocationID2) IS #val(ARGUMENTS.StateID)#>
            AND l.State_ID = #val(ARGUMENTS.LocationID2)#
            <cfelse>
                AND l.Location_ID = #val(ARGUMENTS.LocationID2)#
            </cfif>
    Then, I notice the feature_ID i need to use another logic to show the result. The code is like this
    SELECT r.Restaurant_ID, r.Name, f.Feature
    FROM   Restaurants r
    INNER JOIN Bridge1_Restaurant_Features b ON b.Restaurant_ID = r.Restaurant_ID
    INNER JOIN Features f ON b.Feature_ID = f.Feature_ID
    INNER JOIN
         SELECT Restaurant_ID, COUNT(Feature_ID) AS FeatureCount
         FROM   Bridge1_Restaurant_Features
         <!--- find matching features --->
         WHERE  Feature_ID IN ( <cfqueryparam value="#ARGUMENTS.Feature_ID#" cfsqltype="cf_sql_integer" list="true"> )
        GROUP BY Restaurant_ID
        <!--- having ALL of the requested features --->
         HAVING COUNT(Feature_ID) = <cfqueryparam value="#listLen(ARGUMENTS.Feature_ID)#" cfsqltype="cf_sql_integer">
    ) ck ON ck.Restaurant_ID = r.Restaurant_Id
    I want combine this 2 group together. The second group have to replace
    <cfif ARGUMENTS.Feature_ID IS NOT "">
        AND f.Feature_ID IN (#ARGUMENTS.Feature_ID#)
    </cfif>
    I try few way to group this 2 code, but fail to make it. The code i try is on below, it get error.
    SELECT r.Name , r.Restaurant_ID, f.feature, r.Price_Range, r.Cuisine_ID, c.Cuisine,
            s.State_ID, s.State, l.Location_ID, l.Area, l.State_ID,  r.Location_ID
            FROM Restaurants r, Features f, Cuisine c, State s, Location l
            INNER JOIN Bridge1_Restaurant_Features b ON b.Restaurant_ID = r.Restaurant_ID
            INNER JOIN Features f ON b.Feature_ID = f.Feature_ID
            AND r.Cuisine_ID = c.Cuisine_ID
            AND r.Location_ID = l.Location_ID
            AND l.State_ID = s.State_ID
            <cfif ARGUMENTS.Feature_ID IS NOT "">
            INNER JOIN
                 SELECT Restaurant_ID, COUNT(Feature_ID) AS FeatureCount
                 FROM   Bridge1_Restaurant_Features
                 <!--- find matching features --->
                 WHERE  Feature_ID IN ( <cfqueryparam value="#ARGUMENTS.Feature_ID#" cfsqltype="cf_sql_integer" list="true"> )
                GROUP BY Restaurant_ID
                <!--- having ALL of the requested features --->
                 HAVING COUNT(Feature_ID) = <cfqueryparam value="#listLen(ARGUMENTS.Feature_ID)#" cfsqltype="cf_sql_integer">
            ) ck ON ck.Restaurant_ID = r.Restaurant_Id
            </cfif>
            <cfif ARGUMENTS.Price_Range IS NOT "">
            AND r.Price_Range IN (#ARGUMENTS.Price_Range#)
            </cfif>
            <cfif ARGUMENTS.Cuisine IS NOT "">
            AND r.Cuisine_ID = (#ARGUMENTS.Cuisine#)
            </cfif>
            <cfif val(ARGUMENTS.LocationID2) IS #val(ARGUMENTS.StateID)#>
            AND l.State_ID = #val(ARGUMENTS.LocationID2)#
            <cfelse>
                AND l.Location_ID = #val(ARGUMENTS.LocationID2)#
            </cfif>

    Yeah Adam I am listen to you ! But Finally i solve it.
    This is the code i solve .
    SELECT r.Restaurant_ID, r.Name, f.Feature, r.Price_Range, r.Cuisine_ID, c.Cuisine,
                        l.Location_ID, l.Area, s.State
              FROM   Restaurants r
              <cfif ARGUMENTS.Feature_ID IS NOT "">
              INNER JOIN
                   SELECT Restaurant_ID, COUNT(Feature_ID) AS FeatureCount
                   FROM   Bridge1_Restaurant_Features
                   <!--- find matching features --->
                   WHERE  Feature_ID IN ( <cfqueryparam value="#ARGUMENTS.Feature_ID#" cfsqltype="cf_sql_integer" list="true"> )
                  GROUP BY Restaurant_ID
                  <!--- having ALL of the requested features --->
                   HAVING COUNT(Feature_ID) = <cfqueryparam value="#listLen(ARGUMENTS.Feature_ID)#" cfsqltype="cf_sql_integer">
              ) ck ON ck.Restaurant_ID = r.Restaurant_Id
              </cfif>
              INNER JOIN Location l ON r.Location_ID = l.Location_ID
              INNER JOIN State s ON l.State_ID = s.State_ID
              INNER JOIN Cuisine c ON r.Cuisine_ID = c.Cuisine_ID
              INNER JOIN Bridge1_Restaurant_Features b ON b.Restaurant_ID = r.Restaurant_ID
              INNER JOIN Features f ON b.Feature_ID = f.Feature_ID
              <cfif ARGUMENTS.Cuisine IS NOT "">
              AND r.Cuisine_ID = (#ARGUMENTS.Cuisine#)
              </cfif>
              <cfif ARGUMENTS.Price_Range IS NOT "">
              AND r.Price_Range IN (#ARGUMENTS.Price_Range#)
              </cfif>
              <cfif val(ARGUMENTS.LocationID2) IS #val(ARGUMENTS.StateID)#>
              AND l.State_ID = #val(ARGUMENTS.LocationID2)#
              <cfelse>
                   AND l.Location_ID = #val(ARGUMENTS.LocationID2)#
              </cfif>
    Is it the code can be improve more ?

  • Outer join with Filter condition

    Hi there,
    I need some help with Data Services. I am creating an outer join between two tables and one of them has filter condition but it creates and outerjoin and apply the filter condition to the whole result set.
    SELECT "IWFMR13T_VEH_NTK_TMP1"."ACTY_DT" , "IWFMR13T_VEH_NTK_TMP1"."VEH_CL" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NO" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_NO" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_STRT_DT" , "IWFMR13T_VEH_NTK_TMP1"."FR_SRVC_SEQ_NO" , "IWFMR13T_VEH_NTK_TMP1"."TO_SRVC_SEQ_NO" , "IWFMR13T_VEH_NTK_TMP1"."FR_ACTY_TS" , "IWFMR13T_VEH_NTK_TMP1"."TO_ACTY_TS" , "IWFMR13T_VEH_NTK_TMP1"."MINS_ON_TRN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_STA_CD" , "IWFMR13T_VEH_NTK_TMP1"."MAJ_VEH_CD" , "IWFMR13T_VEH_NTK_TMP1"."VEH_DIST_KM" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NET_TN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_GROS_TN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NTK" , "IWFMR13T_VEH_NTK_TMP1"."VEH_GTK" , "IWFMR13T_VEH_NTK_TMP1"."HLNG_LOCO_MPU" , "IWFMR13T_VEH_NTK_TMP1"."09_HLNG_LOCO_FL" , "IWFMR13T_VEH_NTK_TMP1"."LOCO_MPU" , "IWFMR11T_SGMT_LCNT"."SUM_LOCO_MPU" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_BUS_GRP_CD" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_COAL_MRKR_CD" 
    FROM "DBO"."IWFMR13T_VEH_NTK_TMP1" "IWFMR13T_VEH_NTK_TMP1"
    LEFT OUTER JOIN "DBO"."IWFMR11T_SGMT_LCNT" "IWFMR11T_SGMT_LCNT"
    ON ( "IWFMR11T_SGMT_LCNT"."SRVC_NO" = "IWFMR13T_VEH_NTK_TMP1"."SRVC_NO" ) AND( "IWFMR11T_SGMT_LCNT"."SRVC_STRT_DT" = "IWFMR13T_VEH_NTK_TMP1"."SRVC_STRT_DT" ) AND( "IWFMR11T_SGMT_LCNT"."FR_SRVC_SEQ_NO" = "IWFMR13T_VEH_NTK_TMP1"."FR_SRVC_SEQ_NO" ) AND( "IWFMR11T_SGMT_LCNT"."TO_SRVC_SEQ_NO" = "IWFMR13T_VEH_NTK_TMP1"."TO_SRVC_SEQ_NO" )
    WHERE ( "IWFMR13T_VEH_NTK_TMP1"."09_HLNG_LOCO_FL" = 'Y')
    While, what I need is as under
    SELECT "IWFMR13T_VEH_NTK_TMP1"."ACTY_DT" , "IWFMR13T_VEH_NTK_TMP1"."VEH_CL" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NO" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_NO" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_STRT_DT" , "IWFMR13T_VEH_NTK_TMP1"."FR_SRVC_SEQ_NO" , "IWFMR13T_VEH_NTK_TMP1"."TO_SRVC_SEQ_NO" , "IWFMR13T_VEH_NTK_TMP1"."FR_ACTY_TS" , "IWFMR13T_VEH_NTK_TMP1"."TO_ACTY_TS" , "IWFMR13T_VEH_NTK_TMP1"."MINS_ON_TRN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_STA_CD" , "IWFMR13T_VEH_NTK_TMP1"."MAJ_VEH_CD" , "IWFMR13T_VEH_NTK_TMP1"."VEH_DIST_KM" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NET_TN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_GROS_TN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NTK" , "IWFMR13T_VEH_NTK_TMP1"."VEH_GTK" , "IWFMR13T_VEH_NTK_TMP1"."HLNG_LOCO_MPU" , "IWFMR13T_VEH_NTK_TMP1"."09_HLNG_LOCO_FL" , "IWFMR13T_VEH_NTK_TMP1"."LOCO_MPU" , "IWFMR11T_SGMT_LCNT"."SUM_LOCO_MPU" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_BUS_GRP_CD" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_COAL_MRKR_CD" 
    FROM "DBO"."IWFMR13T_VEH_NTK_TMP1" "IWFMR13T_VEH_NTK_TMP1"
    LEFT OUTER JOIN "DBO"."IWFMR11T_SGMT_LCNT" "IWFMR11T_SGMT_LCNT"
    ON ( "IWFMR11T_SGMT_LCNT"."SRVC_NO" = "IWFMR13T_VEH_NTK_TMP1"."SRVC_NO" ) AND( "IWFMR11T_SGMT_LCNT"."SRVC_STRT_DT" = "IWFMR13T_VEH_NTK_TMP1"."SRVC_STRT_DT" ) AND( "IWFMR11T_SGMT_LCNT"."FR_SRVC_SEQ_NO" = "IWFMR13T_VEH_NTK_TMP1"."FR_SRVC_SEQ_NO" ) AND( "IWFMR11T_SGMT_LCNT"."TO_SRVC_SEQ_NO" = "IWFMR13T_VEH_NTK_TMP1"."TO_SRVC_SEQ_NO" ) AND  ( "IWFMR13T_VEH_NTK_TMP1"."09_HLNG_LOCO_FL" = 'Y')
    Please let me know, how to fix this issue. If you have come across such issue before. If need be I can send you the ATL file for this data flow. 
    BTW, I am using Data Services XI 3.2 (12.2.0.0) and the database is SQL 2005, both on Windows Platform.
    Thanks & regards,
    Doshi Bhavesh

    Hi,
    Use two query transforms;
    First will only connect to IWFMR13T_VEH_NTK_TMP1 and use it to apply filter  "IWFMR13T_VEH_NTK_TMP1"."09_HLNG_LOCO_FL" = 'Y'
    In second query transform perform outer join on IWFMR11T_SGMT_LCNT and output of first query.
    This should give required result.
    If you are using single query transform join will be performed at DB level and if you use custom sql in query transform it will not have increased load on DB. I will recommend to use custom sql to get good performance.
    Sachin

  • Left outer join with multiple conditions

    Is it possible to add to a left outer join (= anyOfAllowingNone) more than the primary condition (in SQL this would be added per "and").
    Background: The execution plan of the produced SQL shows large results on which the final filter is applied although I have conditions that would decrease this last result set much earlier...

    There is no easy way to do this in TopLink expressions, other than including the join in the regular where clause as you have done. Does it make a big impact in the performance of your query?
    <p>
    You could use custom SQL for the query.
    <p>
    Or you could potentially define a OneToOneQueryKey in your TopLink descriptor that includes the additional join criteria and call anyOfAllowingNone using this query key.
    <p>
    <p>---
    <p>James Sutherland

  • Convert SSRS dropdown MDX query to INNER JOIN w/ NONEMPTY? Having hard time with this.

    I'm having an incredibly hard time with this, mostly because I'm very new with MDX.
    I created a simple report (with AdventureWorksDW) whose datasource is an SSAS cube. I select a datekey from the dropdown menu, and the report displays [Measures].[Order Quantity] for that day.
    The problem is that the dropdown displays every single value from the dimdate dimension. DimDate goes from 20050101 to 20201231, so the dropdown is very long.
    How can I alter the SSRS-generated MDX so that it does an INNER JOIN with Fact table and only the dates shown in the dropdown are the ones where there's data in the Fact table?
    Currently, the fact table only has 2 days of data (20141015, 20141016), which means that the dropdown should only display those two dates. I'm including the generated code MDX that populates the dropdown menu:
    WITH MEMBER [Measures].[ParameterCaption] AS
    [Dim Date].[Date Key].CURRENTMEMBER.MEMBER_CAPTION
    MEMBER [Measures].[ParameterValue] AS
    [Dim Date].[Date Key].CURRENTMEMBER.UNIQUENAME
    MEMBER [Measures].[ParameterLevel] AS
    [Dim Date].[Date Key].CURRENTMEMBER.LEVEL.ORDINAL
    SELECT {[Measures].[ParameterCaption],
    [Measures].[ParameterValue], [Measures].[ParameterLevel]}
    ON COLUMNS , [Dim Date].[Date Key].ALLMEMBERS ON ROWS
    FROM [Adventure Works cube]
    Any help is appreciated.
    VM

    Hi vmhatup,
    you can get rid of blank data using nonempty function and get rid of negative values using filter function nonempty should be inside of filter so it applies first, otherwise it is too slow.
    Your statement could look like this
    WITH MEMBER [Measures].[ParameterCaption] AS
    [Dim Date].[Date Key].CURRENTMEMBER.MEMBER_CAPTION
    MEMBER [Measures].[ParameterValue] AS
    [Dim Date].[Date Key].CURRENTMEMBER.UNIQUENAME
    MEMBER [Measures].[ParameterLevel] AS
    [Dim Date].[Date Key].CURRENTMEMBER.LEVEL.ORDINAL
    SELECT {[Measures].[ParameterCaption],
    [Measures].[ParameterValue], [Measures].[ParameterLevel]}
    ON COLUMNS
    , filter(
    nonempty([Dim Date].[Date Key].[Date Key],measures.measureName)
    ,measure.measurename >0
    ON ROWS
    FROM [Adventure Works cube]
    Jiri Neoral

Maybe you are looking for