SELECT Query design with JOINS

Dear Users,
In one of our requirements, we have a SELECT query which joins a few tables together and selects a few fields from each table.
Example: Fields 1,2 and 3 from Table 1
         Fields 4 and 5 from Table 2.
These fields are later displayed in the form of an ALV. However, the end user wants more fields on the output, let's say field 6 from Table 2. Due to this requirement, I have to amend the SELECT query to add field 6 of Table 2.
The above example is simple since it only involves 2 tables. However, in reality, we have a SELECT query with INNER JOINS on more than 6 tables and we don't want to change the code when someone asks for an additional field from one of these tables. Is there any way by which I can design my SELECT query (Using field symbols or dynamic selections etc) such that I don't have to amend the SELECT query and instead I should be able to maintain the field required by the user and it's source table name in a Z-Table and the SELECT automatically picks it up ? Thanks!
Vijay

better you can create a view on your 6 or more tables and select the fields .
Use Select *  from <view name> every time in a select statement.
If you need a additional column then just change the view , there is no need to change of your select query.
with regards
Edited by: Avenai on Jun 28, 2010 2:09 PM

Similar Messages

  • Select query based on joining of tables from different database is taking too long

    Hi Team,
    Select query on table with millions of records is taking very long time. It took 50mins, the below query is joining on multiple table from two databases DB1.dbo.Table1 contains 100 million records and also Table3 and Table4 (of different database) might
    contain close to 1million records.
    Select T1.*
    From DB1.dbo.Table1 T1
    Join DB1.dbo.Table2 T2 on RTRIM(T1.Col3) = RTRIM(T2.Col3)
    Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
    Join Table3 U on CA.Col2 = U.Col2 AND RTRIM(T2.Col2) = U.Col3
    Where U.Col4 NOT IN ('A1', 'A2', 'A3', 'A4', 'A5', 'A6','A7','A8','A9')
    And (T1.flg IS NULL OR T1.flg = 'N')
    And LTRIM(RTRIM(T2.Col2)) NOT IN ('B1','B2')
    How can i improve the performance of this query. Actual thing is update the data in Db1.dbo.table1 based on the conditions but if the select is taking close to 1hr then update will take hours together. Indexes already implemented on all the tables.
    Thanks,
    Eshwar.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

    Thanks.
    Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
    This join is not working with spaces if Rtrim is not used.
    Thanks! Eshwar.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

  • Unable to access Query Designer with RRMX.

    I have intalled Sap GUI 7.0. I am able to run all applications vai Link : START -> ALL PROGRAMES -> BUSINESS EXPLORER -> QUERY DESIGNER.
    But when i try opening query designer from my logon pad with transaction RRMX, the query designer does not work.Kindly guide on the issue.

    You can start the BEx Query Designer using one of the following options:
    &#9679;      Standalone, by choosing Start ® Programs ® Business Explorer ® Query Designer.
    &#9679;      BEx Web Application Designer:
    In the menu bar of the Web Application Designer, you have chosen Extras  ® BEx Query Designer.
    &#9679;      BEx Analyzer:
    You are in an empty cell and have chosen Extras ® Define New Query in the analysis toolbar.
    &#9679;      BEx Report Designer:
    In the menu bar of the Report Designer, you have chosen Extras ® BEx Query Designer.

  • Restricting infoobject in query designer with authorization object

    Hi,
    We have to restrict CUSTOMER infoobject with a authorization object in query designer.
    How to do this task ? Request kindly suggest.

    thr RSSECADMIN tcode. Search with this key word you will get good docs & Wikis in SDN
    bhaskar

  • Query Designer with SAPNW7.01ABAPTrial

    Hello
    I am beginner on SAP BI and I want to know how to get or where to download query designer that can work with SAPNW7.01ABAPTrial. Thanks to reply sooner
    Regards

    Hi,
    Pls go to Service Market Place. www.service.sap.com--> Downloads -> SAP support Packages -> My Companys application component -> BI Addons for SaP GUI -> BI 7.0 Addon for SAP GUI 710/BW 3.5 Addon for SAP GUI 7.10.
    Regards
    CSM Reddy

  • SELECT query - problem with SORT

    Hi,
    Same select query behaves different way on development and quality server
    on Development it returns unsorted and Quality returns sorted
    it can be resolved by SORT but why does it behave differently
    Do you know what is setting in database
    thanks

    From F1 on SELECT:
    Orders the records in a SELECT statement. Without the ORDER-BY clause, the order
    in which the selected lines are supplied is undefined. This means that two similar SELECT
    statements may produce lines in a different order.
    Rob

  • Select query for inner join

    Hi all,
    give me the query with innerjoin
    Based on the input values of Material number (MARC-MATNR) from selection screen check and get the Special Procurement type details from MARC-SOBSL and Material description details from MAKT-MAKTX.
    basha....
    Moderator message - instead of asking, you should try to write the code yourself and get back to the forum if you have a specific question.
    Edited by: Rob Burbank on Apr 19, 2009 4:46 PM

    Hi,
    Please Test the following Sample Code it is according to your requirement hope will solve out your problem,
    TABLES: marc.
    SELECt-OPTIONS somatnr for marc-matnr.
    TYPES: BEGIN OF ty_matnr,
      matnr LIKE marc-matnr,
      sobsl LIKE marc-sobsl,
      maktx LIKE makt-maktx,
      END OF ty_matnr.
    DATA: it_matnr TYPE STANDARD TABLE OF ty_matnr WITH HEADER LINE.
    SELECT marc~matnr marc~sobsl makt~maktx
      into CORRESPONDING FIELDS OF TABLE it_matnr
      from marc INNER JOIN makt on ( marc~matnr eq makt~matnr )
      WHERE marc~matnr in somatnr.
    Best Regards,
    Faisal

  • Issue when suming the field in Select query using inner join

    Hi All,
    SELECT A~OI_SHNUM
           A~FORWAGENT        
           A~ROUTE
           A~SHTYP
           A~DTSHP_EACT
           A~/BIC/GTCLICENS
           A~/BIC/GTCADD04
           A~COMP_CODE
           SUM( C~GRS_WGT_DL )
           C~UNIT_OF_WT
      INTO TABLE I_LAYONE
      FROM ( ( /BIC/ANTCD000200 AS A
      INNER JOIN /BIC/AGSSD000700 AS B ON BOI_SHNUM = AOI_SHNUM )
      INNER JOIN /BIC/AGSSD000600 AS C ON CDELIV_NUMB = BDELIV_NUMB ).
    I need to sum the field C~GRS_WGT_DL
    While compiling it show the error given below
    The field "C~UNIT_OF_WT" from the SELECT list is is missing in the
    GROUP BY clause. is missing in the GROUP BY clause. is missing in the
    GROUP BY clause. is missing in the GROUP BY clause. is missing in the
    GROUP BY clause. is "C~UNIT_OF_W
    with regards,
    Thambe

    Hi,
    Try the following SQL statement. Hope it helps you.
    SELECT A~OI_SHNUM
    A~FORWAGENT
    A~ROUTE
    A~SHTYP
    A~DTSHP_EACT
    A~/BIC/GTCLICENS
    A~/BIC/GTCADD04
    A~COMP_CODE
    SUM( C~GRS_WGT_DL )
    C~UNIT_OF_WT
    INTO TABLE I_LAYONE
    FROM ( ( /BIC/ANTCD000200 AS A
    INNER JOIN /BIC/AGSSD000700 AS B ON BOI_SHNUM = AOI_SHNUM )
    INNER JOIN /BIC/AGSSD000600 AS C ON CDELIV_NUMB = BDELIV_NUMB )
    GROUP BY
    A~OI_SHNUM
    A~FORWAGENT
    A~ROUTE
    A~SHTYP
    A~DTSHP_EACT
    A~/BIC/GTCLICENS
    A~/BIC/GTCADD04
    A~COMP_CODE.
    Murthy.

  • Corrupted Query Designer with strange External Restriction

    Dear Experts,
    I have a dilemma with query, when I run the query in RSRT and debug it with OLAP, in the restriction side it appears to restrict the query with two Attributes which are not even used in my query not also their master-data.
    I have created the same query again but still it gave the same behavior.
    Please help me to remove this dilemma.
    Regards,
    Mohammed

    close all applications re-use RSRT
    hope it works

  • Authorizations to restrict Query Designer with Only Display option

    Hello,
    I have looked all most all possible ways in internet to find out a suggestion/solution for the below. But Invain.
    I would like to know the Transactions, authorization objects and profiles  that are responsible to restrict users not to change and copy queries from QD.
    I need only display option for queries.
    Also,please confirm shall we restrict the same from Transaction SCC4.
    Thanks In Advance.

    Hi there,
    Since you're talking about a QD system, you should lock it in transaction SCC4.
    In case you need to change things in QD without opening the system in SCC4, you can go to transaction rsa1->transport connection and click on Object Changeability. In there you can define what paricular options are "opened for changes" even with SCC4 in close mode.
    Also, for roles having that objects, you should use the authorization object S_RS_COMP and S_RS_COMP1 with Activity with value 02 - Display
    Diogo.

  • Select Query using Joins

    Hi,
    Please give me the Select query
    I have to fetch   EBELN,BUKRS,LIFNR,BSART,EKORG,EKGRP,WAERS,WKURS  from EKKO and
                          EBELP,LGORT,MATKL ,WERKS,BEDNR,IDNLF,BPRME,NETPR   from EKPO and
                         MENGE, SAKTO,AUFNR,ANLN1,GSBER,PS_PSP_PNR                from EKKN and
                         LPEIN,EINDT,SLFDT,                                                                    from EKET.
    I have to fetch all the data into an single internal table(Mandatory) by a select query using Joins.
    EKKO is having EBELN as primary key
    EKPO is having EBELN,EBELP as primary key
    EKKN is having EBELN,EBELP as primary key
    EKET is having EBELN,EBELP as primary key
    Can anybody Please give me the Select query.
    With Regards
    Ajay

    Hi ,
    I am sending this sample coed for the Inner joins .Hope this will help you:
    Inner joins using 3 tables 
    Try this :-
    SELECT stpostlnr stpoidnrk mastmatnr maramtart stpo~menge 
    INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast 
    JOIN stpo ON stpostlnr = maststlnr 
    JOIN mara ON maramatnr = mastmatnr 
    WHERE stpostlty = 'M' "AND stpoidnrk IN s_matnr 
    AND mast~werks = 1000. 
    Here s_matnr is a select-options on the selection-screen. 
    Or this. 
    Code: 
         Select single VbrkBukrs VbrkKunrg    Vbrk~Vbeln 
                       VbrkFkdat VbrkBstnk_Vf Vbrk~Zterm 
                       Tvzbt~Vtext 
                       VbakVbeln VbakBstdk 
                       LikpVbeln Likplfdat    Likp~Lfuhr 
           into w_vbrk 
           from vbrk 
          inner join       Tvzbt on TvzbtZterm        = VbrkZterm      and 
                                    Tvzbt~Spras        = sy-langu 
          Inner join       Vbfa  as SalesLnk 
                                 on SalesLnk~vbeln     = pu_vbeln        and 
                                    SalesLnk~vbtyp_v   = c_order 
                inner join Vbak  on VbakVbeln           = SalesLnkVbelv
          Inner join       Vbfa  as DeliveryLnk 
                                 on DeliveryLnk~vbeln   = pu_vbeln       and 
                                    DeliveryLnk~vbtyp_v = c_Delivery 
                inner join Likp  on LikpVbeln          = DeliveryLnkVbelv 
          where vbrk~vbeln = pu_Vbeln. 
    This code locates sales, delivery and payment terms info from a billing document number. 
    or
    Here, this one also works fine :
    select zfpcdcadivi zfpcdproforma zfpcdfactura zfpcdaniofactura 
    zfpcdmontousd zfpcdmontoap zfpcdebeln zfpcdinco1 
    zfpcdlifnr lfa1name1 zcdvsstatus zfpcdconint 
    into it_lista 
    from zfpcd inner join zcdvs 
    on zfpcdebeln = zcdvsebeln 
    and zfpcdproforma = zcdvsproforma 
    and zfpcdlifnr = zcdvslifnr 
    inner join lfa1 
    on zfpcdlifnr = lfa1lifnr 
    where zcdvs~status = '04'. 
    Also Here is another solution that just uses inner joins:
    SELECT vbakvbeln vbfaerdat INTO (itab-vbeln, itab-wadat)
    FROM ( vbak INNER JOIN vbap
    ON vbapvbeln = vbakvbeln )
    INNER JOIN vbfa ON vbakvbeln = vbfavbelv
    WHERE vbak~kunnr = m_wm AND
    vbak~vbtyp = 'C' AND
    vbfa~erdat IN s_date AND
    vbap~matnr = 'MZ1807F' AND
    vbfaposnv = vbapposnr AND
    vbfa~vbtyp_n = 'J'.
    <REMOVED BY MODERATOR>
    Cheers,
    Chandra Sekhar.
    Edited by: Alvaro Tejada Galindo on Apr 10, 2008 5:20 PM

  • Strange results with Insert statement having select query

    Hi all,
    I am facing a strange issue with Insert statement based on a select query having multiple joins.
    DB- Oracle 10g
    Following is the layout of my query -
    Insert into Table X
    Select distinct Col1, Col2, Col3, Col4, Function(Col 5) from Table A, B
    where trunc(updated_date) > = trunc(sysdate-3)
    and join conditions for A, B
    Union
    Select Col1, Col2, Col3, Col4, Function(Col 5) from Table C, D
    trunc(updated_date) > = trunc(sysdate-3)
    and join conditions for C, D
    Union
    .... till 4 unions. all tables are residing in the local Database and not having records more than 50,000.
    If I execute above insert in a DBMS job, it results into suppose 50 records where as if I execute the select query it gives 56 records.
    We observed following things-
    a) no issue with size of tablespace
    b) no error while inserting
    c) since query takes lot of time so we have not used Cursor and PLSQL block for inserting.
    d) this discrepancy in number of records happens frequently but not everytime.
    e) examined the records left out from the insert, there we couldn't find any specific pattern.
    f) there is no constraint on the table X in which we are trying to insert. Also tables A, B, C....
    I went through this thread -SQL insert with select statement having strange results but mainly users are having either DB Links or comparison of literal dates, in my case there is none.
    Can somebody explain why is the discrepancy and what is the solution for it.
    Or atleast some pointers how to proceed with the analysis.
    Edited by: Pramod Verma on Mar 5, 2013 4:59 AM
    Updated query and added more details

    >
    Since I am using Trunc() in the where clause so timing should not matter much. Also I manually ruled out records which were updated after the job run.
    >
    The first rule of troubleshooting is to not let your personal opinion get in the way of finding out what is wrong.
    Actually this code, and the process it represents, is the most likely CAUSE of the problem.
    >
    where trunc(updated_date) > = trunc(sysdate-3)
    >
    You CANNOT reliably use columns like UPDATED_DATE to select records for processing. Your process is flawed.
    The value of that column is NOT the date/time that the data was actually committed; it is the date/time that the row was populated.
    If you insert a row into a table right now, using SYSDATE (8am on 3/5/2013) and don't commit that row until April your process will NEVER see that 3/5/2013 date until April.
    Here is the more typical scenario that I see all the time.
    1. Data is inserted/updated all day long on 3/4/2013.
    2. A column, for example UPDATED_DATE is given a value of SYSDATE (3/4/2013) in a query or by a trigger on the table.
    3. The insert/update query takes place at 11:55 PM - so the SYSDATE values are for THE DAY THE QUERY BEGAN
    4. The data pull begins at 12:05 am (on 3/5/2013 - just after midnight)
    5. The transaction is COMMITTED at 12:10 AM (on 3/5/2013); 5 minutes after the data pull began.
    That data extract in step 4 will NEVER see those records! They DO NOT EXIST when the data pull query is executed since they haven't been committed.
    Even worse, the next nights data pull will not see them either! That is because the next pull will pull data for 3/5/2013 but those records have a date of 3/4/2013. They will never get processed.
    >
    Job timing is 4am and 10pm EST
    >
    Another wrinkle is when data is inserted/updated from different timezones and the UPDATED_DATE value is from the CLIENT pc or server. Then you can get even more data missed since the client dates may be hours different than the server date used for the data pull process.
    DO NOT try to use UPDATED_DATE type columns to do delta extraction or you can have this issue.

  • Sap bi authorizations issue with query designer..

    i am using bw 3.x and bi 7 query designer with different kind of probs?...
    i am able to see the info provider  in query desinger 3.x. but i can see only cubes .i am not able to find dso or infosets or multiprovider.. can anyone suggest is there any authorizations issues..please suggest.
    and with BI 7 query designer i am not able to see info providers in info areas folder to design a query..
    please suggest if any authorizations should be added or not

    hi suman chakravar,
    thanks for replying,
    can u be little bit clear about the steps.
    i went to tcode su01 and entered profile 0bi_all..it doesnt work.
    and executed tcode su56.there i can find list of BI related authorization profiles
    i added s_rs_all profile to my user. even then i face the same problem.
    i can see only queries in query designer of bi 7 format and i can not view info providers.
    i can view only cube and infosets and i can not view dso and multiproviders in bw 3.x type query designer
    Edited by: satishchow on Dec 14, 2011 3:23 PM

  • Formula Evaluation in Query Designer

    Hi
    In query designer I have Complex formula which is having lot of variables.
    My users are saying some values are incorrect in report output
    Can any one help how can we find the value is calculated in report output for this formula.
    Thanks
    Sudhakar.

    Hi Sudhakar,
    One more way which you can try to find out how the particular Key Figure is been calculated in query designer is as given below:
    1) Go to RSRT
    2) execute your query with option for Query Display As "List"
    3) You will get the query output
    4) In this screen, you will get the button "Key Figure Definition" on the top
    5) Click on this button and there will be a pop up screen to select "Structure Element 1" and "Structure Element 2"
    6) Here for "Structure Element 1" please select the KeyFigure name for which you want to see the calcuation
    7) and click on the "Continue" (Here its blue colored icon)
    8) After this you will get a screen showing KF value that is calculated by query
    9) Drill down the key figure to see "Fixed Fliter" which will show the data selection used to calculate this value. These are nothing but the global filters defined in query
    10) Drill down the KF to see the dynamic filter values i.e. selections with which this KF is restricted in query designer
    With above analysis you can easily trace out how the particular KF is calculated in query designer.
    Regards,
    Geetanjali

  • Error in netweaver BI query designer

    Hi, When we login into BI3 and select Query designer it shows error as given in attached document. I have checked all the services and restarted it bbut still doesnot work. Kindly advice what exactly can be done for this. With Regards

    Hi
    1. What is the version of SAPGUI & patch?
    2. Have you enable the IE 8 Compatibility view settings? kindly follow the link
    https://fortress.wa.gov/ofm/bass/basspr/library/Instructions_on_how_to_switch_IE8_to_compatibility_mode.pdf
    BR
    SS

Maybe you are looking for

  • Multiple desktops keep switching order

    I use multiple desktops (not sure what the feature is called anymore) in 10.8.2.  I have about 4 of them, and for some reason, #2 and #3 keep switching places!  any ideas why?  I just have different browsers, a finder window, (simple stuff) in each o

  • List of Wireless Networks disappear/don't show

    I'm having major problems with my Macbook Pro. It has all the latest upgrades for Leopard (just checked again for updates - nothing more available). This was a native installation of Leopard - not an upgrade from Tiger. When I FIRST start my laptop,

  • ORA-00907: missing right parenthesis

    hi, my requirement is creating xml using dynamic sql .but i got this error please help me. declare l_query varchar2(2000); output clob; begin l_query:='select dbms_xmlgen.getxml('' select empno,to_char(sal,''99,999.99'') salary from emp '') loandetl

  • Why is Macbook Mail suddenly redownloading thousands of old emails?

    Hi everyone, More MacMail weirdness - this time a *major* problem. This morning, no idea why, Mac Mail has suddenly started redownloading emails I received *years* ago, including spam, trash, and junk mail. It's constantly flashing them up on my scre

  • Cannot add songs to my iphone after installing new MAC OS X 10.6

    PLEASE HELP.