Looking of tip on nested select statments

Hi -- I am trying to count the distinct value of field in the table, but when processer get to this line and (b.emplid = z.emplid). It gives me error invalid table name.
I used the z as an alias for the selection...
would you please tell what I am doing wrong.tx
SELECT A.job, sum(decode(sex, 'M', 1, 0)) male_total, sum(decode(sex, 'F', 1, 0)) female_total
FROM DATA B,
(select distinct STDNT_EMPLOYEE A,
WHERE A.YEAR = '2008'
and a.status ='A') z,
and b.emplid = z.emplid
group by a.job

The Toad does not recognize my alias(z) as a table,
and it highlights it as table name error
SELECT A.job, sum(decode(L.sex, 'M', 1, 0))male_total,
sum(decode(L.sex, 'F', 1, 0)) female_total
from admin a, data L
(select distinct STDNT_EMPLOYEE x, from Hire Y
WHERE x.YEAR = '2008'
and a.status ='A') z,
where b.emplid = z.emplid
group by a.job
There's a multitude of basic typos in this code - for instance, the dangling comma in the subquery, the fact that x is a column alias and you use it as a table alias, the fact that there isn't a comma after data L...
STOP POSTING and start properly looking at your code.
Message was edited by:
Dave Hemming
(failed to properly emphasise the important part)

Similar Messages

  • Using nested select in oracle functions

    hi, im new to oracle functions, and im trying to write a function using a nested select statment, but i get the error
    Error: PLS-00428: an INTO clause is expected in this SELECT statement
    can anyone help point out what i am doing wrong, The sql select statment works on a worksheet, so i guess its the way i am using the function
    create or replace function Media_Object_Name(Detail_id Number) return varchar2 as
    Result varchar2(300);
    begin
    select promo_name from promo where promo_id =
    (select promo_id from promo_plan where promo_plan_id =
    (select promo_plan_id from event_promotion where detail_id = Detail_id)) into ;
    return(Result);
    end Media_Object_Name;
    thanks
    james

    The into clause should go here:
    SELECT promo_name
      INTO Result
      FROM promo
    WHERE promo_id = (SELECT promo_id
                         FROM promo_plan
                        WHERE promo_plan_id = (SELECT promo_plan_id
                                                 FROM event_promotion
                                                WHERE detail_id = detail_id));I don't know about your data modell, but are you sure you need nested selects?
    C.

  • Query in select statment

    Hi ,
        what is the difference between,select single and
    select upto one row .
    In a select statment .
    Thanks ,
    shankar.

    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not
    using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key,
    it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key
    supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s)
    you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the
    second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional
    level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause
    If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly: to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that
    are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns
    the first record of the result set.
    Mainly: to check if entries exist.
    You can refer to the below link..
    http://www.sap-img.com/abap/difference-between-select-single-and-select-upto-one-rows.htm

  • Is it possible to nest SELECT statements?

    Greetings community,
    Another newbie’s question it is. Looking tutorials and some posts here I’ve been advised not to pull entire table through the local network, and torture client machines’ processors and memory. It’s been said that better solution is to
    pull just one part of the table.
    So, imagine this: you want to make a part of your app that would allow your user to view list of orders. So you put one data grid view on the form, pull last 20 headers from the table into it and leave to user to choose one to be opened
    in another form. If user doesn’t find header they want, they press page up for example and previous 20 headers are loaded into data grid view. Of course, user could filter headers list by customer, or by distribution lane (having all customers residing in
    one part of the town), or whatever more, but let’s not complicate things at this moment, because I’m practically in the beginning.
    I’m trying to make a stored procedure that would load penultimate 20 headers when user presses page up. So, not knowing any better, I created table variable that has the same structure as Orders table with one difference: OrderID column,
    which is identity (auto incremented) in Orders table, here is simply defined as bigint not null. Community member Visakh16 warned me few months ago it’s the bad practice to put self-incrementing columns in table variables.
    At this moment there’s a query on my screen, which waits to become store procedure. After boring part with table variable definition, it goes like this:
    INSERT INTO @OrdersTemp SELECT TOP 40 * FROM dbo.Orders ORDER BY OrderID DESC
    SELECT TOP 20 * FROM @OrdersTemp ORDER BY OrderID ASC
    To put that simply, I pull last 40 headers into table variable, and then pull first 20 from there. This thing works, and I just have to replace 40 with parameter, for every page up or down.
    Now I have few questions.
    -Is there some better way (considering performance) to achieve that? Here is the place where I wanted to ask the question from the title of the post. I don’t know much about T-SQL, and I’m not sure about the proper syntax to nest SELECT
    statements, if something like that is even possible
    -Is there any better way (some built-in function) to find about the count of the rows in one table than
    SELECT COUNT(OrdersID) FROM dbo.Orders
    Thanks for any suggestions.

    Hi Erland,
    Sorry for the very late reply, but I said that I would start another thread when I find more free time to dedicate it to this, so I didn’t really expected you to reply anymore. I didn’t really check here for more than a week, and I glanced
    at mail accidentally.
    As for the negative result I got, its measurement unit is microsecond, so it doesn’t go out of margins you had experienced.
    As for the number of cores, you got me surprised there. I use express edition of SQL server. Last time I checked was SQL server 2012 express, and in specifications it said that express edition is limited to 1 processor core, 1GB of RAM
    and creates up to 10GB database file. I don’t believe they changed any of those specifications. It was generous enough when they doubled size of DB file few editions ago. Still, it appears that “one processor core for express edition” statement has some gray
    areas in it.
    However, at this moment I’m just learning, and I just wanted some way to test how efficient my queries are. I don’t have a real biz problem to solve. I don’t expect that any real performance problem should rise in years of everyday work
    of populating database. What I expect is performance impact when it comes to creating reports, but after all, I don’t think that my boss would create reports by himself. I believe that creating reports would be my task, and I will be doing it after hours,
    being the only user at the moment. Or maybe I could make de-normalized copy of database that would be populated after hours to make it possible for my boss to get his reports faster by himself, as I’ve heard that was the way of making BI in older non-express
    editions.
    So, I do suggest that we finally close this thread for sake of other readers. I’ll start another one with this subject when I find the time to do it.
    Again, thanks for being with me along this journey.

  • Performance Problem with Nested Select

    I have an urgent performance question, I run a nested select like this one
      SELECT tabname
               INTO ls_dd02l
               FROM dd02l
               WHERE tabname LIKE c_feld
               AND   buffered IS NOT NULL.
          SELECT tabname fieldname keyflag position
                 INTO CORRESPONDING FIELDS OF ls_dd03l
                 FROM dd03l
                 WHERE tabname   = ls_dd02l-tabname
                 AND   fieldname IN ('MANDT', 'CLIENT', 'CLNT')
                 AND   keyflag   = 'X'.
            IF ( sy-subrc EQ 0 ).
              wa-tabname   = ls_dd03l-tabname.
              wa-fieldname = ls_dd03l-fieldname.
              wa-keyflag   = ls_dd03l-keyflag.
              wa-position  = ls_dd03l-position.
              APPEND wa TO itab.
            ENDIF.
          ENDSELECT.
        ENDSELECT.
    It is taking about 20sec, which is much too long.
    How can I improve the performance.
    Points rewarded!
    S.B.

    Hi Siegfried,
    As Vinay said  u can use INNER JOIN to get the data from both database tables
    or u can use FOR ALL ENTRIES statement.
    You can use the option FOR ALL ENTRIES to replace nested select loops by operations on internal tables. This can significantly improve the performance for large sets of selected data.
    The above statement is from Library. Please check this link
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3a1f358411d1829f0000e829fbfe/content.htm
    Tabular Conditions sub heading
    SELECT a~tabname
           b~fieldname
           b~keyflag
           b~position
        FROM dd02l as a INNER JOIN dd03l as b
          ON a~tabname = b~tabname
         INTO TABLE itab
       WHERE a~tabname LIKE c_feld
         AND buffered IS NOT NULL
         AND fieldname IN ('MANDT', 'CLIENT', 'CLNT')
         AND keyflag   = 'X'.
    OR
    SELECT tabname
           INTO TABLE lt_dd02l
           FROM dd02l
           WHERE tabname LIKE c_feld
           AND   buffered IS NOT NULL.
    IF NOT lt_dd02l IS INITIAL.
          SELECT tabname fieldname keyflag position
                 INTO CORRESPONDING FIELDS OF TABLE itab
                 FROM dd03l
                 FOR ALL ENTRIES IN lt_dd02l
                 WHERE tabname   = lt_dd02l-tabname
                 AND   fieldname IN ('MANDT', 'CLIENT', 'CLNT')
                 AND   keyflag   = 'X'.
    ENDIF.
    Please check this link
    /people/rob.burbank/blog/2007/03/19/joins-vs-for-all-entries--which-performs-better
    You have to look at the primary keys..
    MANDT
    STLTY
    STLNR
    STLAL
    STLKN
    STASZ
    MANDT
    STLTY
    STLNR
    STLKN
    STPOZ
    You need the stlty for both tables stas and stpo
    The on condition between stas and stpo is obvious, will help a
    bit.
    It would be much better, if you could add it to the WHERE Condition.
    Do you know it?
    If not, then as the BOM categories are not so many,
    Try
    select distinct stlty
    from stas.
    and add the values to you where condition as
    AND s1-stlty in ( ....... )
    This should improve the performance.
    I don't kknow whether the BOM Categories can change in future.
    instead of a fixed in, you could add a subselect from a customizing table.
    I am quite confident that the solution I proposed will be much faster than the FOR ALL ENTRIES.
    But with more complicated joins you really have to try it.
    There is no general rule about the number of tables in a join, there are perfectly running joins with 5 tables
    and there are porblems with 2 tables.
    You must analyze the indexes, it it is clear which index will support the accesses then it will work fine.
    The FOR ALL ENTRIES is by construction much slower!
    Best regards,
    raam

  • Table list for select statment

    hello all,
    I been trying to setup a plsql statment to run a select statment from tables that are in a list.
    this is what I have done so far as a test and it is not letting me do it and I don't know why can anyone point me in the right direction.
    declare
    cursor main_log is
    select *
    from joseph_w.table_name_list;
    cml main_log%rowtype;
    var1 varchar2(35);
    var2 varchar2(35;
    begin
    open main_log;
    fetch main_log into cml;
    var1 := cml.schema_name;
    var2 := cml.table_name;
    select *
    from var1.var2;
    close main_log;
    end;
    thanks

    In PL/SQL you cannot just "select", as PL/SQL is a server sided language. You must use a record or variable to hold the selected data. Anyway, for selecting from different tables dynamically, you can use (Native) Dynamic SQL or Ref Cursors. Take a look at the documentation, especially the "PL/SQL User's Guide and Reference":
    http://www.oracle.com/pls/db102/portal.portal_db?selected=1
    Regards,
    Gerd

  • DB Adapter Query - Polling using nested select

    When polling a table to initiate a BPEL process, can I use a nested select in the expression.

    The visual expression builder does not currently support this so you need to specify the raw sql directly.
    If you use the DeletePollingStrategy there is a way you can specify the exact sql string for both the 'select' and the after read 'delete'. So if you write the where clause yourself it can contain nested selects.
    This is the readme from the new PureSQLSelect database adapter sample. Also you may want to look at the PureSQLPolling sample.
    This sample shows you how you can bypass the designer's visual where clause builder to specify arbitrarily complex sql strings for your selects.
    Like the other samples, this sample uses the basic Movies schema.
    The Steps:
    Create a basic select. Made sure it has the same name and number of input parameters as you will need for your sql string. In this case create a single input parameter and call it 'genre_param'.
    Create a trivial where clause in the wizard expression builder using genre_param. I.e. genre.like(genre_param)
    Ideally run the sample once just to make sure everything else works and to get a template SQL. The select ... FROM ... part will be the same.
    Open the toplink_mappings.xml file. Look for an element called <database-query>. There will likely only be one. A sample is presented here:
    <query-manager>
    <descriptor-query-manager>
    <existence-check>Check cache</existence-check>
    <descriptor-named-queries>
    <database-query>
    <query-name>selectByGenreSelect</query-name>
    <query-should-maintain-cache>true</query-should-maintain-cache>
    <cascade-policy>1</cascade-policy>
    <should-bind-all-parameters>undefined</should-bind-all-parameters>
    <should-cache-statement>undefined</should-cache-statement>
    <should-use-wrapper-policy>true</should-use-wrapper-policy>
    <query-timeout>0</query-timeout>
    <query-arguments>
    <string>genre_param</string>
    </query-arguments>
    <query-argument-types>
    <values>java.lang.String</values>
    </query-argument-types>
    <reference-class>PureSQLSelect.Movies</reference-class>
    <refresh-identity-map>false</refresh-identity-map>
    <cache-usage>2</cache-usage>
    <lock-mode>0</lock-mode>
    <distinct-state>0</distinct-state>
    <query-indirection>
    <in-memory-query-indirection>
    <policy>0</policy>
    </in-memory-query-indirection>
    </query-indirection>
    <main-expression>
    <expression>
    <operator-type>AND</operator-type>
    <expression-list>
    <expression>
    <operator-type>Like</operator-type>
    <first-argument>
    <argument>
    <query-key-name>genre</query-key-name>
    <outer-join>false</outer-join>
    <to-many>false</to-many>
    <argument-class>oracle.toplink.tools.workbench.expressions.QueryableArgumentRepresentation</argument-class>
    </argument>
    </first-argument>
    <second-argument>
    <argument>
    <parameter-name>genre_param</parameter-name>
    <argument-class>oracle.toplink.tools.workbench.expressions.ParameterArgumentRepresentation</argument-class>
    </argument>
    </second-argument>
    <expression-class>oracle.toplink.tools.workbench.expressions.BinaryExpressionRepresentation</expression-class>
    </expression>
    </expression-list>
    <expression-class>oracle.toplink.tools.workbench.expressions.CompoundExpressionRepresentation</expression-class>
    </expression>
    </main-expression>
    <type>oracle.toplink.queryframework.ReadAllQuery</type>
    </database-query>
    </descriptor-named-queries>
    </descriptor-query-manager>
    </query-manager>
    We want to switch this query from using a high-level expression to a pure sql string. You will remove the <main-expression> element and replace it with a <sql-string> element of your own devising.
    Your replacement should look something like this:
    <query-manager>
    <descriptor-query-manager>
    <existence-check>Check cache</existence-check>
    <descriptor-named-queries>
    <database-query>
    <query-name>selectByGenreSelect</query-name>
    <query-should-maintain-cache>true</query-should-maintain-cache>
    <cascade-policy>1</cascade-policy>
    <should-bind-all-parameters>undefined</should-bind-all-parameters>
    <should-cache-statement>undefined</should-cache-statement>
    <should-use-wrapper-policy>true</should-use-wrapper-policy>
    <query-timeout>0</query-timeout>
    <sql-string>SELECT DELETED, DIRECTOR, GENRE, LAST_UPDATED, RATED, RATING, RELEASE_DATE, RUN_TIME, SEQUENCENO, STARRING, STATUS, SYNOPSIS, TITLE, TOTAL_GROSS, VIEWER_RATING FROM MOVIES WHERE (upper(GENRE) LIKE upper(concat(concat('%', #genre_param), '%'))) ORDER BY TOTAL_GROSS desc</sql-string>
    <query-arguments>
    <string>genre_param</string>
    </query-arguments>
    <query-argument-types>
    <values>java.lang.String</values>
    </query-argument-types>
    <reference-class>PureSQLSelect.Movies</reference-class>
    <refresh-identity-map>false</refresh-identity-map>
    <cache-usage>2</cache-usage>
    <lock-mode>0</lock-mode>
    <distinct-state>0</distinct-state>
    <query-indirection>
    <in-memory-query-indirection>
    <policy>0</policy>
    </in-memory-query-indirection>
    </query-indirection>
    <type>oracle.toplink.queryframework.ReadAllQuery</type>
    </database-query>
    </descriptor-named-queries>
    </descriptor-query-manager>
    </query-manager>
    Gotchas:
    The tempation to start writing pure sql may be terrible to some, but it was intentionally left out of the wizard for good reasons. Please be wary of the following when specifying pure sql:
    -There is a way to set the pure sql string in the Mapping Workbench, but when you edit the partnerlink to refresh the toplink_mappings.xml you may get an exception due to the query being in a pure sql format. For this reason you need to manually edit the toplink_mappings.xml, and again every time your run the wizard and hit finish after that.
    -The #genre_param is a TopLink convention for writing a sql string which still takes parameters. At runtime if you enter 'Action' in the bpel console, you will see this sql:
    SELECT DELETED, DIRECTOR, GENRE, LAST_UPDATED, RATED, RATING, RELEASE_DATE, RUN_TIME, SEQUENCENO, STARRING, STATUS, SYNOPSIS, TITLE, TOTAL_GROSS, VIEWER_RATING FROM SYSTEM.MOVIES WHERE (GENRE LIKE ?)
    bind => [Action]
    The #genre_param gets replaced with the value of the input parameter genre_param.
    -When specifying pure sql you should be aware of the following:
    -maintenance issues
    -loss of database platform independence
    -The sql needs to conform with the way TopLink works. It is recommended that you do not change the SELECT ... FROM ... part of the query. TopLink's design is to read from one table at a time. If an Employee has an Address, then the Address is read with a hidden relationship query. There are two advanced TopLink features which optimize reading from multiple tables, called joinedAttribute and batchAttribute reading, but the combination of these features with raw sql was not explored here. So to avoid danger you can only really affect the top level query, and only rewrite the where clause.
    -The pure sql route does not interact with most TopLink features, especially batch reading (on by default), and can not be combined with the following:
    -LogicalDeletePollingStrategy
    -SequencingPollingStrategy (LastUpdated, LastReadId, File)
    These features extend the selection criteria at runtime.

  • Sql Query Error (9i) nested select with OleDB

    I have the following query which works fine when used with Sqlplus, but fails when called from within crytal reports (using an OleDB connection). I saw an open Oracle bug number 3025605 on some website, but haven't been able to look up any additional information on the error. The query fails with Ora-00972.
    SELECT "CLIENTS"."CLTFIRSTNAME",
    "CLIENTS"."CLTLASTNAME",
    "CLIENTS"."CLTMIDDLENAME",
    "SCHEDULE"."SCSESSIONDATE",
    (SELECT r.REMPFIRSTNAME||' '||r.REMPLASTNAME
    FROM REFAGENCYEMPLOYEES R WHERE "R"."REMPLOYEEID" = "SCHEDULE"."SCREFPERSON1ID") REFAGENT1,
    (SELECT r.REMPFIRSTNAME||' '||r.REMPLASTNAME
    FROM REFAGENCYEMPLOYEES R WHERE "R"."REMPLOYEEID" = "SCHEDULE"."SCREFPERSON2ID") REFAGENT2,
    "CODELOOKUP"."CODELISTNAME"
    FROM "POBJS"."CLIENTS" "CLIENTS",
    "POBJS"."SCHEDULE" "SCHEDULE",
    "POBJS"."CODELOOKUP" "CODELOOKUP"
    WHERE ("CLIENTS"."CLIENTID"="SCHEDULE"."SCCLIENTID")
    AND ("SCHEDULE"."SCEXAMTYPE"="CODELOOKUP"."CODEVALUE")
    AND "CODELOOKUP"."CODELISTNAME"='EXAM TYPES'
    Thanks for any help.

    Thanks for the information. I worked around the problem by calling a function that basically runs the nested select statement and returns a value.
    pobjs.getrname("SCHEDULE"."SCREFPERSON1ID") AS AGENT1,
    "CODELOOKUP"."CODELISTNAME"
    FROM "POBJS"."CLIENTS" "CLIENTS", ........

  • Performace problem in a select statment how to imporve the performance

    fist select statment
    SELECT    a~extno
              a~guid_lclic       " for next select
              e~ctsim
              e~ctsex
    *revised spec 3rd
              f~guid_pobj
              f~amnt_flt
              f~amcur
              f~guid_mobj
              e~srvll     "pk
              e~ctsty     "PK
              e~lgreg  "PK
      INTO TABLE gt_sagmeld
      FROM /SAPSLL/LCLIC  as a
      INNER JOIN /sapsll/tlegsv as e on elgreg = algreg
    * revised spec 3rd
      inner join /sapsll/legcon as f on fguid_lclic = aguid_lclic   " for ccngn1 selection
      inner join /sapsll/corcts as g on gguid_pobj = fguid_pobj
                               where   a~extno in s_extno.
      sort gt_sagmeld by guid_lclic guid_pobj.
    lgreg ctsty srvll
      delete adjacent duplicates from gt_sagmeld comparing guid_lclic guid_pobj.
    it selects about 20 lakh records
    belos select statment whichs is taking time as it is based on the entreis of gt_sagmeld
    select /sapsll/corpar~guid_mobj
                /sapsll/corpar~PAFCT
                but000~bpext
                but000~partner
                /sapsll/corpar~parno
                into table gt_but001
        from    /sapsll/corpar
        INNER join but000  on  but000partner = /sapsll/corparparno
        for all entries in gt_sagmeld
        where  /sapsll/corpar~guid_mobj = gt_sagmeld-guid_mobj
        and    /sapsll/corpar~PAFCT = 'SH'.
       SELECT /sapsll/cuit~guid_cuit         " PK
              /sapsll/cuit~QUANT_FLT         " to be displayed
              /sapsll/cuit~QUAUM             " to be displayed
              /sapsll/cuit~RPTDT             " to be displayed
             /sapsll/cuhd~guid_cuhd         " next select
              /sapsll/cuit~guid_pr           " next select
      INTO table gt_sapsllcuit
      FROM  /sapsll/cuit
    inner join /sapsll/cuhd on /sapsll/cuitguid_cuhd = /sapsll/cuhdguid_cuhd
      FOR all entries in gt_sagmeld
      WHERE /sapsll/cuit~guid_cuit = gt_sagmeld-guid_pobj.
      Delete adjacent duplicates from gt_sapsllcuit[].
           if not gt_sapsllcuit[] is initial.

    hi navenet
    that didnt worked
    we need to try ur range options
    but not sure what you told in the last mail as not clear with range can u pls eloboragte more i am pasting the full code here
    SELECT     a~extno
               a~guid_lclic       " for next select but000
               e~ctsim
               e~ctsex
               e~srvll
               e~ctsty
               e~lgreg
      INTO TABLE gt_sagmeld
      FROM /SAPSLL/LCLIC  as a
      INNER JOIN /sapsll/tlegsv as e on elgreg = algreg
                               where   a~extno in s_extno.
    sort gt_sagmeld by guid_lclic.
    delete adjacent duplicates from gt_sagmeld comparing all fields.
      IF not gt_sagmeld[] is initial.
      SELECT  /sapsll/legcon~guid_lclic
              /sapsll/legcon~guid_pobj
              /sapsll/legcon~amnt_flt
              /sapsll/legcon~amcur
               but000~bpext
               *revised spec
               /sapsll/corpar~PAFCT
              /sapsll/legcon~guid_mobj
             /sapsll/cuit~guid_cuit
      INTO TABLE gt_but000
      FROM /SAPSLL/LEGCON
      for all entries in gt_sagmeld
      where /SAPSLL/legcon~guid_lclic = gt_sagmeld-guid_lclic.
            IF NOT GT_BUT000[] IS INITIAL.
           sort gt_but000 by guid_mobj.
           delete adjacent duplicates from gt_but000 comparing guid_mobj.
         select /sapsll/corpar~guid_mobj
                /sapsll/corpar~PAFCT
                /sapsll/corpar~parno
                into table gt_but001
        from    /sapsll/corpar
        for all entries in gt_but000
        where  /sapsll/corpar~guid_mobj = gt_but000-guid_mobj.
       and    /sapsll/corpar~PAFCT = 'SH'.
    DELETE gt_but001 where PAFCT <> 'SH'.
    *sort gt_corpar by parno.
    *delete adjacent duplicates from gt_corpar comparing parno.
    *select gd000~partner
          gd000~bpext
         from gd000 into table gt_but001
    for all entries in gt_corpar
    where  gd000~partner = gt_corpar-parno.
    my ultimat aim is to select bpext from gd000
    can u please explain how to use ranges here and what is the singnificance and how ill i read the data from the final  table if we use ranges
    regards
    Nishant

  • Select statment - fill internal table

    Hi,
    I have following situation:
    TYPES: BEGIN OF q_data,
             i_lqua LIKE lqua,
             v_xxx(20) type c,
           END OF q_data.
    DATA: a_data TYPE STANDARD TABLE OF q_data.
    Now I would write a select statment and fill the table a_data.
    select lqua~matnr lqua~werks... from lqua inner join mch1 into (i_lqua-matnr, i_lqua-werks.....)...
    Is it possible to write a statement without writing the whole structure (all the names of columns) of lqua in the SQL-statement (lquamatnr lquawerks lqua~........)?
    Thanks
    Michael

    1. you can write that but i think you have to write that in SELECT ...ENDSELECT.
    select lquamatnr lquawerks... from lqua inner join mch1 into (i_lqua-matnr, i_lqua-werks.....
    append i_lqua.
    endselect.
    2. OR you can use INTO CORRESPONDING FIELDS OF TABLE
       select lquamatnr lquawerks... from lqua inner join mch1 into corresponding fields of table i_lqua.

  • Using distinct and orderby in the select statment

    Hi All,
    Can anyone tell me what is the purpose of using distinct and orderby in the select statment.

    Hi,
    Using the distinct function with more than one column yields some substantial results. SQL will return the rows with distinct or unique combinations of those columns. Assume this same employee table has another column including the salary of each employee. With the use of the distinct function we can pull a list of unique job titles - salaries.
    SQL Code:
    SELECT DISTINCT job_titles, salary FROM employees;
    SQL has returned all the rows with unique combinations of job titles and salaries. Any duplicate combinations of job titles and salaries will be ignored. For example if we had two CEOs in the table making the same salary each year, only one row would be returned but if we had two CEOs with different salaries, both rows would be returned.
    Order by
    The SQL ORDER BY clause comes in handy when you want to sort your SQL result sets by some column(s). For example if you want to select all the persons from the already familiar Customers table and order the result by date of birth, you will use the following statement:
    SELECT * FROM Customers
    ORDER BY DOB
    As you can see the rows are sorted in ascending order by the DOB column, but what if you want to sort them in descending order? To do that you will have to add the DESC SQL keyword after your SQL ORDER BY clause:
    SELECT * FROM Customers
    ORDER BY DOB DESC
    If you don't specify how to order your rows, alphabetically or reverse, than the result set is ordered alphabetically, hence the following to SQL expressions produce the same result:
    SELECT * FROM Customers
    ORDER BY DOB
    SELECT * FROM Customers
    ORDER BY DOB ASC
    You can sort your result set by more than one column by specifying those columns in the SQL ORDER BY list. The following SQL expression will order by DOB and LastName:
    SELECT * FROM Customers
    ORDER BY DOB, LastName
    if its useful reward points

  • Select statment - where clause

    Hello experts,
    I want to write a select statment,
    e.g.
    select * from pa0001 where ename like '%Rahul%'.
    so this stamemt will give me all DB rows in which ename contains Rahul but i also want rows those are having rahul or rAhul or raHul or RAhul or RAHul or RaHul like wise....
    can u plz help me on this ???

    Hi
    Find the below code which may be useful for your requirement
    ranges:r_sel for lfa1-name1.
    data:v_name(5) type c value 'laxmi'.
    data:len type i,
    v_num type i,
    v_num1 type i,
    v_num2 type i,
    v_name1(5) type c,
    v_name2(5) type c,
    v_name_final(7) type c,
    v_char type c.
    len = strlen( v_name ).
    clear:v_name1,v_name2,v_name_final,v_num,v_num1,v_num2.
    v_num1 = len.
    do len times.
      v_num1 = v_num1 - 1.
      v_char = v_name+v_num(1).
      v_num2 = v_num.
      v_num = v_num + 1.
      if v_num1 is initial.
        clear:v_name1.
      else.
        v_name1 = v_name+v_num(v_num1).
      endif.
      if v_num2 is not initial.
        v_name2 = v_name+0(v_num2).
      endif.
      translate v_char to upper case.
      concatenate '' v_name2 v_char v_name1 '' into v_name_final.
      r_sel-option =  'CP'.
      r_sel-sign = 'I'.
      r_sel-low = v_name_final.
      clear:r_sel-high.
      append r_sel.
      translate v_char to lower case.
      concatenate '' v_name2 v_char v_name1 '' into v_name_final.
      r_sel-option =  'CP'.
      r_sel-sign = 'I'.
      r_sel-low = v_name_final.
      clear:r_sel-high.
      append r_sel.
    enddo.
    Use range parameter in your select statement.
    Regards
    Sripal

  • Select statment Query

    Hi,
    I am devloping Query  with the table DBERCHZ1
    it  having  two fields
        V_ ABRMENGE        value  456
       N_ ABRMENGE        value   0.67899
    Here i want  to print as  456.67899  with  one  select  statment.
    is  any way  to sum  in select  statment.
    Thanks

    Hi,
    I have just given a code snippet similar to your requirement.
    DATA:   average TYPE p DECIMALS 2,
            sum     TYPE p DECIMALS 2.
    SELECT AVG( luggweight ) SUM( luggweight )
      INTO (average, sum)
      FROM sbook.
    WRITE: / 'Average:', average,
           / 'Sum    :', sum.
    Just replace with your variables and let me know if it works.
    Thanks,
    Harini

  • Dynamic field in select statment.

    Hello,
    I created a report in which i have two checkboxes in the selection screen. The first checkbox is for the option to bring or not, initial purchase requisitions (BANFN) from EKPO and the second is to bring initial or not, RFQs
    (ANFNR). I want the select statment to have this form:
    select ...
    from ekpo
    into g_table
    where ..
    and dynamic field = " ".
    Can this be done ?
    i tried to put it as a string but it didnt work. (data: dynamic field type string value "EKPO-BANFN")
    P.S i know that it can be by writing the same select code twice.
    I just wonder if this can be done by this way
    \Regards.

    Hey Nick,
    I have more conditions than the one i said before , should all be in the lv_where_clause ?
    check my code.
    DATA: G_CHBFLD type STRING.
    G_CHBFLD = 'P~BANFN = '' " '.
    FORM SELECT_DATA_EKPO_EKKO.
      SELECT  .....
          FROM EKPO AS P INNER JOIN EKKO AS K
            ON PEBELN = KEBELN
              INTO CORRESPONDING FIELDS OF TABLE GT_EKPOEKKO
                WHERE K~EBELN IN S_EBELN
                AND K~AEDAT IN S_AEDAT
                AND K~BSTYP IN S_BSTYP
                and ( G_CHBFLD ) .   -
    > //DEBUGER ")" is not a valid comparison operator. comparison operator.

  • Fix Variable in select statment

    Hi,
    Can we define a variable in select statment .
    Example :
    Select firstname , lastname
    from employees;
    in this simple select statment can we define x as number ?

    Maybe
    SQL> variable x number
    SQL> exec :x := 3
    PL/SQL procedure successfully completed.
    SQL> select :x x, last_name from employees where rownum <= 3
    X                                LAST_NAME               
    3                                King                    
    3                                Kochhar                 
    3                                De Haan                 
    3 rows selected.

Maybe you are looking for

  • IPod Shuffle not syncing music

    iTunes says that the iPod Shuffle is synced. I have selected a song to put on the iPod but I can not find the command to 'sync.'  I have tried selecting a song and dragging it to the iPod but when I disconnect the iPod Shuffle and pulg in the earphon

  • How do i restore a project in final cut pro x?

    Hi, I want to revert to a previous version of my project from a few hours previous (I don't like the changes I have made). I know Final Cut Pro X autosaves but how do I go back in time to get to my previous saves?

  • How can I get the size of all lines or the last line number in a DB?

    I want to display a certain number of lines from a DB. But before I fetch them out, I must know how many lines of this DB has. I donnot know if there is some methods have this function. I know the last() method can move the cursor to the last line, b

  • The bottom of my macbook is falling off.

    The bottom of my macbook is falling off.

  • Additonal VGA monitor showing in Display properties.

    I have a problem, I am currently running Window 7 Pro 64 and when i restarted my laptop it now has an additional monitor showing in the display properties.  I do not have an external VGA monitor connected to it, and I have tried to remove the display