Operation in Select Statement

Hi,
In an ABAP select statement, how to do operations on two columns of a dictionary transparent table(say division or multiplication on two column values) ?
Reward points will be awarded .
TIA
Regards,
Anindita

hi,
see the below link
i hope it will useful for u .
http://help.sap.com/saphelp_nw04/helpdata/en/62/10a423384746e8bf5f15ccdd36e8b1/content.htm
SELECT AVG(salary) FROM employees
SELECT COUNT(*) FROM employees
SELECT COUNT(DISTINCT employee_name) FROM employees
SELECT employee_name, salary + benefit
               FROM employees
               WHERE salary < 0.8 *
                  ( SELECT MAX( salary ) FROM employees )
Arithmetic Expressions. For all employees that have a salary not exceeding 80% of the salary of the maximum salary of all employees, this query returns the name of the employee and the sum of its salary and its benefit.
reward if its useful
Edited by: p541399 on Feb 28, 2008 5:49 PM

Similar Messages

  • Cp  operator in select statement

    Hi i am getting error when i write the below select statement, could any one please let me know, how to use  CP operator in select statement
    my code was
    SELECT lifnr name1 FROM lfa1 INTO CORRESPONDING
            FIELDS OF TABLE lt_lfa1 
            WHERE lifnr CP lv_lifnr AND
                  name1 CP  lv_name1.
    Thanks
    Srini
    Message was edited by: Manish Kumar <spoonfeeding, thread locked by moderator>
    Message was edited by: Manish Kumar

    either you have select-options with lifnr and name and use them in the below query as
    SELECT lifnr name1 FROM lfa1 INTO CORRESPONDING
            FIELDS OF TABLE lt_lfa1 
            WHERE lifnr in s_lifnr AND
                  name1 in s_name1.
    else you need to declare internal tables with structure as below..
    DATA: begin of ls_user1,
        sign type c,
        option(2) type c,
        low(90) type c,
        high(90) type c,
       end of ls_user1.
    data: lt_lifnr like ls_user1 occurs 0,
             lt_name1 like ls_user1 occurs 0.
    and then populate these as
    ls_user1-sign = 'I'.
    ls_user1-option = 'CP'.
    ls_user1-low = '*'.  populate with whatever pattern you want
    APPEND ls_user1 TO lt_lifnr
    similarly do it for NAME1 and use them in the query.

  • Offset operation in select statements where clause

    dear experts,
        if i use offset operation in select query , syntactically giving
        me a warning message.
        how to avoid warning message
        without using another internal table populated with  only  jtab+0(10).  
       ex:
              select field1 field2
                        into table   itab
                        from ztable1
                        for all entries in jtab
                        where field =  jtab+0(10).
    thanks in advance.

    No need to populate another internal table...
    when populating jtab from database select ur field twice
    structure for jtab..
    types: begin of ty_jtab,
              field type ...
              field1 type char10,
            end of ty_jtab.
    populate the field twice..
       select ...
                 field
                 field
    into table jtab
    Now u can use the field field1 in the next select
    select field1 field2
    into table itab
    from ztable1
    for all entries in jtab
    where field = jtab-field1.

  • How to use OracleParameter whith the IN Operator of select statement

    Hi,
    I am having problems using the OracleParameter when used in a query with a IN operator.
    Following Example:
    oraCommand.Parameters.Add(":List", strMylist ); //or Array???
    The SQL command:
    SELECT * FROM XXX WHERE XXX.YYY IN (:List);
    What datatype must the value of :List be?
    regards
    Stefan

    Let's use a collection of User Defined Types (UDT's).
    First create a table with 1 million rows:
    create table employees (id number(10) not null primary key, name varchar2(100) );
    insert into employees
    select level l, 'MyName'||to_char(level)
    from dual connect by level <= 1e6;
    1000000 rows created
    commit;
    exec dbms_stats.gather_schema_stats(USER, cascade=>TRUE);No we turn to the C# code:
    Let's select employees with id's 3 and 4.
    Collection type MDSYS.SDO_ELEM_INFO_ARRAY is used because if we use this already predefined Oracle type we don't have to define our own Oracle type. You can fill collection MDSYS.SDO_ELEM_INFO_ARRAY with max 1048576 numbers.
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
        [OracleCustomTypeMappingAttribute("MDSYS.SDO_ELEM_INFO_ARRAY")]
        public class NumberArrayFactory : IOracleArrayTypeFactory
          public Array CreateArray(int numElems)
            return new Decimal[numElems];
          public Array CreateStatusArray(int numElems)
            return null;
        private void Test()
          OracleConnectionStringBuilder b = new OracleConnectionStringBuilder();
          b.UserID = "sna";
          b.Password = "sna";
          b.DataSource = "ora11";
          using (OracleConnection conn = new OracleConnection(b.ToString()))
            conn.Open();
            using (OracleCommand comm = conn.CreateCommand())
              comm.CommandText =
                  @" select  /*+ cardinality(tab 10) */ *  " +
                  @" from employees, table(:1) tab " +
                  @" where employees.id = tab.column_value";
              OracleParameter p = new OracleParameter();
              p.OracleDbType = OracleDbType.Array;
              p.Direction = ParameterDirection.Input;
              p.UdtTypeName = "MDSYS.SDO_ELEM_INFO_ARRAY";
              p.Value = new Decimal[] { 3, 4 };
              comm.Parameters.Add(p);
              int numPersons = 0;
              using (OracleDataReader reader = comm.ExecuteReader())
                while (reader.Read())
                  MessageBox.Show("Name " + reader[1].ToString());
                  numPersons++;
              conn.Close();
        }The index on employees.id isn't used when one omits hint /*+ cardinality(tab 10) */. This index is created by Oracle because id is the primary key column.
    Edited by: wateenmooiedag on Dec 30, 2009 2:45 AM

  • Select Statement Blocking Delete Operation

    Hi Experts,
    In a Single table am trying to do delete operation but it has been blocked by simple select query.
    Database setting : Read Committed Snapshot already set to ON for that database.
    Any Idea why SELECT blocking DELETE.
    FYI : Before Select statement I could noticed the following setting "set transaction isolation level  read committed".
    Kindly Advise
    Regards,
    Nandhu

    FYI : Before Select statement I could noticed the following setting "set transaction isolation level  read committed".
    Hi NandhuJana,
    1. Did you read
    Uri Dimant's response?
    Please try to remove this statement and check again
    2. When we ask you for DDL+DML , the idea is to let us the option to (1) reproduce the issue in some cases, (2) get the best information which is the real database structure, queries, etc'. In this case for example I do not see the isolation level statement
    in your code and we need it to understand what is happening :-) The order and structure (nested transactions for example) of statements is what important here.
    3. you can check your isolet level using one of those options to make sure what is going in your script:
    SELECT TRANSACTION_ISOLATION_LEVEL = CASE transaction_isolation_level
    WHEN 0 THEN 'Unspecified'
    WHEN 1 THEN 'ReadUncommitted'
    WHEN 2 THEN 'ReadCommitted'
    WHEN 3 THEN 'Repeatable'
    WHEN 4 THEN 'Serializable'
    WHEN 5 THEN 'Snapshot'
    END
    FROM sys.dm_exec_sessions
    where session_id = @@SPID
    GO
    DBCC USEROPTIONS WITH NO_INFOMSGS
    GO
    I hope this is helpful :-)
      Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

  • Select statement operators in ecc 6.

    Hi Experts,
    I have a small doubt about the '>=' ( greater than or equal to ) operator usage in select statement. Is this operator by any chance perform not as desired in ECC 6.0. Is it a good option to use 'GE' instead of '>='. ?
    It may sound a bit awkward, but still I would like to know. I am facing a situation, which could be related to this. An early response would be highly appreciated.
    I would request,you NOT TO REPLY with links/explanations which says how to use select statement. Only answer if you have the  answers related to this query.
    Regards,
    Sandipan

    >
    Jaideep Sharma wrote:
    > Hi,
    > The only difference is GE will take a little more time than >= as system need to convert the keyword into actual operator when fetching data from Database.
    >
    > KR Jaideep,
    ????? Every Open SQL statements is translated to the SQL slang the underlying database is talking regardless if you type GE or >=
    If the result differs using >= or GE i would open a call at SAP instead of asking in SDN.

  • Select statement in a function does Full Table Scan

    All,
    I have been coding a stored procedure that writes 38K rows in less than a minute. If I add another column which requires call to a package and 4 functions within that package, it runs for about 4 hours. I have confirmed that due to problems in one of the functions, the code does full table scans. The package and all of its functions were written by other contractors who have been long gone.
    Please note that case_number_in (VARCHAR2) and effective_date_in (DATE) are parameters sent to the problem function and I have verified through TOAD’s debugger that their values are correct.
    Table named ps2_benefit_register has over 40 million rows but case_number is an index for that table.
    Table named ps1_case_fs has more than 20 million rows but also uses case_number as an index.
    Select #1 – causes full table scan runs and writes 38K rows in a couple of hours.
    {case}
    SELECT max(a2.application_date)
    INTO l_app_date
    FROM dwfssd.ps2_benefit_register a1, dwfssd.ps2_case_fs a2
    WHERE a2.case_number = case_number_in and
    a1.case_number = a2.case_number and
    a2.application_date <= effective_date_in and
    a1.DOCUMENT_TYPE = 'F';
    {case}
    Select #2 – runs – hard coding values makes the code to write the same 38K rows in a few minutes.
    {case}
    SELECT max(a2.application_date)
    INTO l_app_date
    FROM dwfssd.ps2_benefit_register a1, dwfssd.ps2_case_fs a2
    WHERE a2.case_number = 'A006438' and
    a1.case_number = a2.case_number and
    a2.application_date <= '01-Apr-2009' and
    a1.DOCUMENT_TYPE = 'F';
    {case}
    Why using the values in the passed parameter in the first select statement causes full table scan?
    Thank you for your help,
    Seyed
    Edited by: user11117178 on Jul 30, 2009 6:22 AM
    Edited by: user11117178 on Jul 30, 2009 6:23 AM
    Edited by: user11117178 on Jul 30, 2009 6:24 AM

    Hello Dan,
    Thank you for your input. The function is not determinsitic, therefore, I am providing you with the explain plan. By version number, if you are refering to the Database version, we are running 10g.
    PLAN_TABLE_OUTPUT
    Plan hash value: 2132048964
    | Id  | Operation                     | Name                    | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT              |                         |   324K|    33M|  3138   (5)| 00:00:38 |       |       |
    |*  1 |  HASH JOIN                    |                         |   324K|    33M|  3138   (5)| 00:00:38 |       |       |
    |   2 |   BITMAP CONVERSION TO ROWIDS |                         |     3 |     9 |     1   (0)| 00:00:01 |       |       |
    |*  3 |    BITMAP INDEX FAST FULL SCAN| IDX_PS2_ACTION_TYPES    |       |       |            |          |       |       |
    |   4 |   PARTITION RANGE ITERATOR    |                         |   866K|    87M|  3121   (4)| 00:00:38 |   154 |   158 |
    |   5 |    TABLE ACCESS FULL          | PS2_FS_TRANSACTION_FACT |   866K|    87M|  3121   (4)| 00:00:38 |   154 |   158 |
    Predicate Information (identified by operation id):
       1 - access("AL1"."ACTION_TYPE_ID"="AL2"."ACTION_TYPE_ID")
       3 - filter("AL2"."ACTION_TYPE"='1' OR "AL2"."ACTION_TYPE"='2' OR "AL2"."ACTION_TYPE"='S')
    Thank you very much,
    Seyed                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to model in OWB if you have a subquery in your select statement? (11.2)

    Which operator (is it the Table operator) to use if I have a subquery as part of my select statement? (The way I do it works, but is not elegant. What I do is create a table for the subquery and than join that with the other sources to point to my target.) But, would appreciate the best way with OWB's features.
    Here is the entire SQL (including the subquery):
    SELECT to_numbe (null), course_id
    at.book, lp.NAME,
    (select b.pricing from qp_pricing_attributes b
    where b.list_id = ll.list_id and b.product = at.product) sign,
    ll.operand AS price, lhb.comments
    FROM
    pricing_attribs at,
    list_lines ll,
    list_h lp,
    list_b lhb
    WHERE 1 = 1
    and ll.list_line_id = atrib.list_line_id
    AND ll.list_header_id = lp.list_header_id
    AND lp.list_header_id = lhb.list_header_id
    Thanks you.

    Hi
    Doesn't need to be a table in the target. Let's take a very simple example, let's say you wanted to do the following;
    select ename,(select dname from dept d where d.deptno=e.deptno) from emp e
    Then DEPT is your lookup table and EMP is your driving table.
    1. Add EMP on to the canvas.
    2. Add in lookup operator
    3. Bind lookup to DEPT
    4. Hit finish
    5. Map EMP.DEPT to DEPT.INGRP1 (the lookup operator)
    6. Edit lookup operator, on Lookup Conditions tab set DEPTNO for lookup column, and DEPTNO for input attribute
    7. Lookup complete now
    You can add in a target table operator and map from the source EMP table and the output attributes of the lookup operator. you can change step 4 to carry on through wizard and define lookup, but I have chosen to do 5, to automatically get the names and datatypes of the inputs. There are lot of other options now in 11gR2 in the lookup.
    Hope this makes sense.
    Cheers
    David

  • Bind Variable in SELECT statement and get the value  in PL/SQL block

    Hi All,
    I would like  pass bind variable in SELECT statement and get the value of the column in Dynamic SQL
    Please seee below
    I want to get the below value
    Expected result:
    select  distinct empno ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    100, HR
    select  distinct ename ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    TEST, HR
    select  distinct loc ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    NYC, HR
    Using the below block I am getting column names only not the value of the column. I need to pass that value(TEST,NYC..) into l_col_val variable
    Please suggest
    ----- TABLE LIST
    CREATE TABLE EMP(
    EMPNO NUMBER,
    ENAME VARCHAR2(255),
    DEPT VARCHAR2(255),
    LOC    VARCHAR2(255)
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (100,'TEST','HR','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (200,'TEST1','IT','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (300,'TEST2','MR','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (400,'TEST3','HR','DTR');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (500,'TEST4','HR','DAL');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (600,'TEST5','IT','ATL');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (700,'TEST6','IT','BOS');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (800,'TEST7','HR','NYC');
    COMMIT;
    CREATE TABLE COLUMNAMES(
    COLUMNAME VARCHAR2(255)
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('EMPNO');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('ENAME');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('DEPT');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('LOC');
    COMMIT;
    CREATE TABLE DEPT(
    DEPT VARCHAR2(255),
    DNAME VARCHAR2(255)
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('HR','HUMAN RESOURCE');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('MR','MARKETING');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
    COMMIT;
    PL/SQL BLOCK
    DECLARE
      TYPE EMPCurTyp  IS REF CURSOR;
      v_EMP_cursor    EMPCurTyp;
      l_col_val           EMP.ENAME%type;
      l_ENAME_val       EMP.ENAME%type;
    l_col_ddl varchar2(4000);
    l_col_name varchar2(60);
    l_tab_name varchar2(60);
    l_empno number ;
    b_l_col_name VARCHAR2(255);
    b_l_empno NUMBER;
    begin
    for rec00 in (
    select EMPNO aa from  EMP
    loop
    l_empno := rec00.aa;
    for rec in (select COLUMNAME as column_name  from  columnames
    loop
    l_col_name := rec.column_name;
    begin
      l_col_val :=null;
       l_col_ddl := 'select  distinct :b_l_col_name ,pr.dept ' ||'  from emp pr, dept ps where   ps.dept like ''%IT'' '||' and pr.empno =:b_l_empno';
       dbms_output.put_line('DDL ...'||l_col_ddl);
       OPEN v_EMP_cursor FOR l_col_ddl USING l_col_name, l_empno;
    LOOP
        l_col_val :=null;
        FETCH v_EMP_cursor INTO l_col_val,l_ename_val;
        EXIT WHEN v_EMP_cursor%NOTFOUND;
          dbms_output.put_line('l_col_name='||l_col_name ||'  empno ='||l_empno);
       END LOOP;
    CLOSE v_EMP_cursor;
    END;
    END LOOP;
    END LOOP;
    END;

    user1758353 wrote:
    Thanks Billy, Would you be able to suggest any other faster method to load the data into table. Thanks,
    As Mark responded - it all depends on the actual data to load, structure and source/origin. On my busiest database, I am loading on average 30,000 rows every second from data in external files.
    However, the data structures are just that - structured. Logical.
    Having a data structure with 100's of fields (columns in a SQL table), raise all kinds of questions about how sane that structure is, and what impact it will have on a physical data model implementation.
    There is a gross misunderstanding by many when it comes to performance and scalability. The prime factor that determines performance is not how well you code, what tools/language you use, the h/w your c ode runs on, or anything like that. The prime factor that determines perform is the design of the data model - as it determines the complexity/ease to use the data model, and the amount of I/O (the slowest of all db operations) needed to effectively use the data model.

  • HOW CAN I  USE MULTIPLE INNERJOINS IN A SINGLE SELECT STATEMENT?

    HI,
    I AM SHABEER AHMED,
    I AM GETTING AN ERROR WHILE I ATTEMPT TO EXECUTE A SELECT STATEMENT WITH MULTIPLE INNER JOINS . BECOZ I WANT TO FETCH ITEM DATA, PARTNER DATA  BASED ON HEADER DATA .
    THEN OF COURSE I HAVE FETCH DATA FROM VBAK VBAP VBKD SO LZ SEND ME THE SOLUTION.
    BYE

    Hi,
    1.Just see this:
    SELECT * INTO CORRESPONDING FIELD OF TABLE itab
    FROM t1 INNER JOIN t2 ON t1f4 EQ t2f4
    INNER JOIN t3 ON t2f5 EQ t3f5 AND
    t2f6 EQ t3f6 AND
    t2f7 EQ t3f7.
    2.But better to use for all entries.It increases the performance.
    FOR ALL ENTRIES
    Tabular Conditions
    The WHERE clause of the SELECT statement has a special variant that allows you to derive conditions from the lines and columns of an internal table:
    SELECT ... FOR ALL ENTRIES IN <itab> WHERE <cond> ...
    <cond> may be formulated as described above. If you specify a field of the internal table <itab> as an operand in a condition, you address all lines of the internal table. The comparison is then performed for each line of the internal table. For each line, the system selects the lines from the database table that satisfy the condition. The result set of the SELECT statement is the union of the individual selections for each line of the internal table. Duplicate lines are automatically eliminated from the result set. If <itab> is empty, the addition FOR ALL ENTRIES is disregarded, and all entries are read.
    The internal table <itab> must have a structured line type, and each field that occurs in the condition <cond> must be compatible with the column of the database with which it is compared. Do not use the operators LIKE, BETWEEN, and IN in comparisons using internal table fields. You may not use the ORDER BY clause in the same SELECT 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.
    Example for ALL ENTRIES
    DATA: TAB_SPFLI TYPE TABLE OF SPFLI,
    TAB_SFLIGHT TYPE SORTED TABLE OF SFLIGHT
    WITH UNIQUE KEY TABLE LINE,
    WA LIKE LINE OF TAB_SFLIGHT.
    SELECT CARRID CONNID
    INTO CORRESPONDING FIELDS OF TABLE TAB_SPFLI
    FROM SPFLI
    WHERE CITYFROM = 'NEW YORK'.
    SELECT CARRID CONNID FLDATE
    INTO CORRESPONDING FIELDS OF TABLE TAB_SFLIGHT
    FROM SFLIGHT
    FOR ALL ENTRIES IN TAB_SPFLI
    WHERE CARRID = TAB_SPFLI-CARRID AND
    CONNID = TAB_SPFLI-CONNID.
    LOOP AT TAB_SFLIGHT INTO WA.
    AT NEW CONNID.
    WRITE: / WA-CARRID, WA-CONNID.
    ENDAT.
    WRITE: / WA-FLDATE.
    ENDLOOP.
    INNER JOINS
    In a relational database, you normally need to read data simultaneously from more than one database table into an application program. You can read from more than one table in a single SELECT statement, such that the data in the tables all has to meet the same conditions, using the following join expression:
    SELECT...
    FROM <tab> INNER JOIN <dbtab> AS <alias> ON <cond> <options>
    where <dbtab> is a single database table and <tab> is either a table or another join expression. The database tables can be specified statically or dynamically as described above. You may also use aliases. You can enclose each join expression in parentheses. The INNER addition is optional.
    A join expression links each line of <tab> with the lines in <dbtab> that meet the condition <cond>. This means that there is always one or more lines from the right-hand table that is linked to each line from the left-hand table by the join. If <dbtab> does not contain any lines that meet the condition <cond>, the line from <tab> is not included in the selection.
    The syntax of the <cond> condition is like that of the WHERE clause, although individual comparisons can only be linked using AND. Furthermore, each comparison must contain a column from the right-hand table <dbtab>. It does not matter on which side of the comparison it occurs. For the column names in the comparison, you can use the same names that occur in the SELECT clause, to differentiate columns from different database tables that have the same names.
    The comparisons in the condition <cond> can appear in the WHERE clause instead of the ON clause, since both clauses are applied equally to the temporary table containing all of the lines resulting from the join. However, each join must contain at least one comparison in the condition <cond>.
    Example for INNER JOINS
    REPORT demo_select_inner_join.
    DATA: BEGIN OF wa,
    carrid TYPE spfli-carrid,
    connid TYPE spfli-connid,
    fldate TYPE sflight-fldate,
    bookid TYPE sbook-bookid,
    END OF wa,
    itab LIKE SORTED TABLE OF wa
    WITH UNIQUE KEY carrid connid fldate bookid.
    SELECT pcarrid pconnid ffldate bbookid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM ( ( spfli AS p
    INNER JOIN sflight AS f ON pcarrid = fcarrid AND
    pconnid = fconnid )
    INNER JOIN sbook AS b ON bcarrid = fcarrid AND
    bconnid = fconnid AND
    bfldate = ffldate )
    WHERE p~cityfrom = 'FRANKFURT' AND
    p~cityto = 'NEW YORK' AND
    fseatsmax > fseatsocc.
    LOOP AT itab INTO wa.
    AT NEW fldate.
    WRITE: / wa-carrid, wa-connid, wa-fldate.
    ENDAT.
    WRITE / wa-bookid.
    ENDLOOP.
    Regards,
    Shiva Kumar(Reward if helpful).

  • Case or decode in select statement for comparison

    Hi,
    How can I do a comparison
    like
    if sal < 50, output 1.1 * comm
    if sal > 50 and < = 100 output 1.2 * comm
    else output comm
    in a single select statement.
    I tried using case and decode but I am not sure how to use it in comparison operations.
    Please help

    use the 'case' construct:
    SELECT
    NORMAL_FIELD
    , (CASE
    WHEN (SAL < 50) THEN 1.1 * COMM          
    WHEN (SAL > 50) AND (SAL <= 100) THEN 1.2 * COMM
    ELSE COMM                    
    END
    ) AS CALCULATED_COMM
    FROM
    TB_xxxx
    WHERE xxxx
    hope this helps

  • How to use column name as variable in select statement

    hi,
    i want to make a sql query where in select statement using variable as a column name. but its not working plz guide me how can i do this.
    select :m1 from table1;
    regards

    Hi,
    Is this what you want..
    SQL> select &m1 from dept;
    Enter value for m1: deptno
    old   1: select &m1 from dept
    new   1: select deptno from dept
        DEPTNO
            10
            20
            30
            40
    SQL> select &m1 from dept;
    Enter value for m1: dname
    old   1: select &m1 from dept
    new   1: select dname from dept
    DNAME
    ACCOUNTING
    RESEARCH
    SALES
    OPERATIONS
    SQL> select &&m1 from dept;
    Enter value for m1: loc
    old   1: select &&m1 from dept
    new   1: select loc from dept
    LOC
    NEW YORK
    DALLAS
    CHICAGO
    BOSTON
    SQL> select &&m1 from dept;
    old   1: select &&m1 from dept
    new   1: select loc from dept
    LOC
    NEW YORK
    DALLAS
    CHICAGO
    BOSTONIf you use single '&' then each time you fire the query, It will ask for the new value..
    But if you will use double '&&' the value of m1 will be persistent across the session..
    Twinkle

  • How to use SET ID in select statement of SQ02

    Hi,
    I have a infoset, where for one of my Zfield, i have writen a select statement in order to get my ouput.
    if aufk-aufnr = 'XYZ'.
      select sum( FKBTR ) from fmifiit into zfmifiit
      where fikrs = aufk-kokrs
      and fipex IN capex
      and wrttp NE '51'.
    endif.
    For the above statement, i have created (with 10 single values, table name FMCI, field name FIPEX)  a SET id named CAPEX and used with IN operator.
    But when i generating the infoset i am getting error like below
    The IN operator with "CAPEX" is followed neither by an internal table nor by a value list
    I was using IN opeartor for set ids during validation / substitutions, where if i have to validate multiple single values.
    What to do here?
    Regards,
    Srinu

    [OPEN-SQL|http://help.sap.com/abapdocu_70/en/ABENOPEN_SQL_GENERAL.htm] set of statement, [SELECT|http://help.sap.com/abapdocu_70/en/ABAPWHERE.htm] statement, [WHERE|http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP.htm] addition requires a selection table (type range, [WHERE - IN seltab |http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_SELTAB.htm]) of parameter and not a set. We are in Abap here, not in a Customizing screen
    You have to convert the set to a selection table in an ABAP coding before using it in a SELECT statement.
    (Check FM like G_SET_TREE_IMPORT to import definition of set (values and intervals) and map them to a select-table, or ask a developper to perform it, look at G_SET_TREE_IMPORT -> select statement)
    Regards,
    Raymond

  • Index not being used in Select statement

    Friends
    I have the following SQL statement:
    SELECT
    a.acct,
    a.date_field,
    UPPER(b.feegroup) feegrp,
    SUM (a.fee1) fee1,
    SUM (a.fee2) fee2,
    SUM (a.fee3) fee3
    FROM table1 a, table2 b
    WHERE 1 = 1
    AND a.fee_id = b.fee_id
    GROUP BY a.acct, a.date_field, b.feegroup;
    Both the tables have index on fee_id column. When I run the explain plan for this statement, I am getting the following output:
    Operation | Option | Object Name | Position
    SELECT STATEMENT | | | 560299
    HASH | GROUP BY| |1
    TABLE ACCESS | FULL| table2 | 1
    TABLE ACCESS | FULL| table1 | 2
    Why Oracle is not using the index?
    Edited by: darshilm on Dec 10, 2009 3:56 PM

    The proposed plan is the optimal according to your current conditions in the "where clause" where you have only the equality join condition and therefore the CBO can use HASH JOIN. Using any kind of index access would just increase the amount of required work unless you would add some very restrictive conditions which will select rows from relatively small amount of blocks. Here I have to mention that what really counts in the CBO cost calculation is the amount of blocks accessed and not the number of rows. The "currency" for I/O in Oracle is a block and not a row. CBO always uses an assumption that there is nothing in the buffer cache and it will have to perform a physical read for every block.
    How many blocks will actually be accessed depends on the data distribution. It can happen that every single row that you have to retrieve resides in a different block and although you access only 1000 rows out of a million row table you would have to visit almost every block of that table. For such a situation a FULL TABLE SCAN is the best access path and Oracle will use multiblock I/O for that. On the other side you can have those 1000 rows only in a few blocks and then the index access would be the most appropriate one. For index access Oracle uses single block I/O. Usually the actual situation is somewhere between this two extreme situations. But you can run some tests by yourself and see when an index access will be replaced by a full table scan while you will make your predicates less selective.
    HTH, Joze
    Co-author of the forthcoming book "Expert Oracle Practices"
    http://www.apress.com/book/view/9781430226680
    Oracle related blog: http://joze-senegacnik.blogspot.com/
    Blog about flying: http://jsenegacnik.blogspot.com/
    Blog about Building Ovens, Baking and Cooking: http://senegacnik.blogspot.com

  • Query regarding Oracle SQL select statement

    Hi,
    How does Oracle ensures a consistent snapshot with the select statement
    without locking the table. My question is summarized with an example below:
    1. At time T1, Oracle select statement is fired and is fetching the result.
    2. At time T2, some DML operation is performed on the same table on which
    the select was executed and a commit was fired.
    3. At time T3, The Oracle select statement (Step 1) completes.
    My question is whether the records of transaction at time T2 will be visible at time T3 or not?
    If "not", then does it mean that Oracle retrieves the rows from the time of last commit.
    I would also like to know if for the above mechanism, Oracle would make use of the rollback segemt to access the rows at a particular instant of time.
    TIA
    Regards,
    Raj

    This is called Read Consistency in the oracle. Its all about SCN before starting the transaction.
    Lets say
    1. T1 executs SELECT statement on EMP table.
    2. T2 made an update on the EMP and commited.
    But, T1 only still sees only old image of the data not the new one. This is called read consistency.
    You will be having two images in the buffer, one is consistent and changed image.
    When the T1 give SELECT statement it notes the SCN of the transaction. Read oracle document about read consistency.
    SJH.

Maybe you are looking for

  • One Bank Account used by Multiple Company Codes - BRS Issue

    Dear All We have a scenario where 1 bank account is maintained under different company codes and used for business purpose.  In this scenario we are able to do Funds Transfer without any issue. When we are going to do BRS, there is a issue.  When we

  • Error Message at Project File Start Up

    Hello, I'm running Premiere (5.5) on a Dual Core MAC (6GB of RAM) I'm working on a project that recently received a 'serious error' message and 'Adobe Premiere needs to close'.  Upon re-opening the project, I get this strange message: /Volumes/BuildD

  • Bridge CC won't display my Sony a99 .ARW files.

    Hi All, Up until recently, Bridge displayed my .ARW files no problem. However, now I only get a generic windows 8 icon. I have updated to the latest ACW as well as made sure CC and all apps are up to date. Still no dice. Some direction would be great

  • TS4337 Ical/applescript/animator can a customised event with added fields be generated?

    Yet again i find myself trawling the Internet to find the best solution to my quest. I run my own business and share jobs with a select amount of people through iCal on our iphone's ipad's and Macbooks as do my associate's. Currently we use the gener

  • NoClassDefFoundError when trying to use a bytebuffer

    Hey Guys, So im trying to use a bytebuffer and when i try to import import java.nio.*;it compiles but i keep getting this error when i try and run the program: Exception in thread "main" java.lang.NoClassDefFoundError: ByteTest Any ideas? Thanks so m