Select query with variable no of conditions

Hi,
I want to write a select query such that the conditions mentioned under WHERE clause can be variable .like :
Select * from TABLE where F1 = var1 and F2 = var2 and F3 = var3.
Now on the basis of some conditons the equations in where clause should be used.Say condition is variable value >6.
Now in this case ,if
var1 =7 var2 =3 var3 = 8 then the query shud behave like
select * from TABLE where F1 = var1 and F3 = var3
if :
var1 =3 var2 = 4 var3 =3 the :
select * from TABLE
But only one query is to be wrote that satisfies all of these
thanx
Edited by: aachal on Feb 4, 2011 11:36 AM

Hi Aachal,
Use Dynamic select statement.
Ex:
data : lv_wherecond type string.
Select * from TABLE where ( lv_wherecond ).
Before Select stmt, code as follows.
if var1 > 6.
       if lv_wherecond is initial.
          F1 = var1.
       else.
          concatenate lv_wherecond ' and F1 = var1'  into lv_wherecond.
       endif.
elseif var 2 > 6.
        if lv_wherecond is initial.
           F2 = var2
        else.
           concatenate lv_wherecond ' and F2 = var2'  into lv_wherecond.
       endif.
elseif var3 > 6.
      same as above ..
endif.
Hope it helps..
Regards,
Sravan Guduru.

Similar Messages

  • Dynamic select query with dynamic where condition

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

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

  • BDC select query with addition based on all If conditions

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

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

  • Absolute dynamic select query with dynamic join and where

    Has anyone ever tried creating an absolutely dynamic SELECT query with dynamic Join and Where conditions.
    I have a requirement of creating such a query in an Utility Class, and i have written the code. But its throwing my sysntax errors.
    Please let me know where am I going wrong OR is it really possible to create such a dynamic Query??
        SELECT (FIELDS) INTO TABLE IT_TABLES
          FROM ( (ME->TABLE1)  inner join ( me->table2 )
          on ( on_condition ) )
          WHERE (me->where_fields).
    Ags.

    It worked for me in a following way:
    select * into corresponding fields of table <result_table>
            from (join_string)
            where (l_where).
    Where the contents of join_string were dynamically build using concatenation. So it will be something like
    concatenate ME->TABLE1 'as a INNER JOIN' me->table2 'as b ON (' into join_string separated by space.
    <...>
    add here matching/reference colums, something like
    concatenate 'a~' me->TABLE1_JOIN_COL into temp1.
    concatenate 'b~' me->TABLE2_JOIN_COL into temp2.
    concatenate join_string temp1 '=' temp2 into join_string separated by space.
    <...>
    concatenate join_string ')' into join_string separated by space.
    And then use similar approach for l_where variable.

  • Issue in select query with where clause

    Hi guys,
    I'm facing an issue while using select query with the where clause. When I'm selecting all the data from the table it returns the correct result. But when I'm using the where clause to get the specific rows from the table it returns no rows. But the data I'm trying to fetch using the where condition exists in the table.
    Here is my query which causing the issue,
    select * from mytable where myfield = 'myvalue'
    But if I use the following query it returns the result correctly.
    select * from mytable
    Also the myfield value 'myvalue' exists in the table.
    I have tried by running this query in both SQL Developer and SQL Plus. I have tried this query in mssql as well. It works perfectly and returns correct result sets for both the queries I have mentioned above. I'm unable to predict the issue as I'm new to ORACLE. Please help.
    Thanks,
    Ram.

    Hi Ram,
    I experienced an issue similar to this with a varchar2 field. Some of our records had a hidden newline character at the end of them, which was making queries like the one below fail:
    select * from employees
    where email = '[email protected]'The best way I found to detect this was to use
    select 'XX'||email||'XX' from employeesTo make sure that there were no newlines. But that is just a guess. If you could provide some example table data and the outputs of your selects, it would be helpful.
    Jeff

  • How to write XSJS Select Query with input parameters

    Hello Experts,
    I am creating a xsjs file and in that file I am trying to write a Select Query based on a Calculation View
    I have tried it the following way:
    var query = 'SELECT TOP 100 \"Name\", \"Address\", \"City\", \"Country\" FROM \"_SYS_BIC\".\"Test.HL/AddressView\"'
        + 'WITH PARAMETERS(\'PLACEHOLDER\' = (\'$$P_Name$$\', \' Akhil \'),'
      + '\'PLACEHOLDER\' = (\'$$P_City$$\', \' Lucknow \'))';
    But it gives me the "Mixed spaces and tabs error".
    How should I write XSJS Select Query with input parameters?
    Regards,
    Rohit

    >But it gives me the "Mixed spaces and tabs error".
    Mixed spaces and tabs has nothing to do with the syntax of the statement. You used both spaces and the tab in the content - which JSLint doesn't like.  Remove the beginning spaces of each line and use only one or the other.
    The actual syntax of your statement doesn't look right.  The problem is that you are escaping the \ when you don't need to if you are using ' instead of " for your string.  You escape with \" in the first line but then escape with \' in the 2nd and 3rd line.  That is going to cause serious parsing problems with the command.

  • I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year

    I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year

    Hi Arun ,
    Can you explain little bit more ??
    what is account doc no? 
    what are the transactions should be displayed in your output??
    -Rajesh N

  • How to re-write this big SELECT Query with INNER JOINs?

    Hi Experts
    I have a performance killer SELECT query with an inner join of 3 tables u2013 VBAP, VBAK and VBEP together, which populates records to an internal table INT_COLL_ORD. Based on these records selected, in another SELECT query, records are fetched from VBUK table to the internal table INT_VBUK.
    SELECT A~VBELN A~POSNR A~MATNR A~KWMENG A~KBMENG A~ERDAT A~ERZET A~PSTYV D~AUART E~ETTYP E~EDATU
    INTO TABLE INT_TAB_RES
    FROM VBAP AS A INNER JOIN VBAK AS D
    ON D~VBELN EQ A~VBELN AND D~MANDT EQ A~MANDT
    INNER JOIN VBEP AS E
    ON E~VBELN EQ A~VBELN AND E~POSNR EQ A~POSNR AND E~MANDT EQ A~MANDT
    WHERE  A~VBELN IN s_VBELN AND
           D~auart in s_auart AND
           D~vkorg in s_vkorg AND
           D~vbtyp eq 'C'     AND
           ( ( matnr LIKE c_prefix_sp AND zz_msposnr NE 0 AND kbmeng EQ 0 )
           OR ( matnr LIKE c_prefix_fp AND kwmeng NE A~kbmeng ) ) AND
           A~ABGRU EQ SPACE AND
           A~MTVFP IN R_MTVFP AND
           A~PRCTR IN R_PRCT AND
           E~ETENR EQ '1'.
    SORT INT_COLL_ORD BY VBELN POSNR ETTYP.
    DELETE ADJACENT DUPLICATES FROM INT_TAB_RES COMPARING VBELN POSNR.
    CHECK NOT INT_TAB_RES [] IS INITIAL.
    SELECT VBELN UVALL CMGST INTO TABLE INT_VBUK
    FROM VBUK FOR ALL ENTRIES IN INT_TAB_RES
    WHERE VBELN = INT_TAB_RES-VBELN AND UVALL NE 'A'.
    Now, the requirement is:
    I want to split this query. Like, first join VBAK and VBUK first. With this selection, go to the inner join of VBAP and VBEP (on key VBELN) to get the results. How can I re-write this Query?
    Please help.
    Thx n Rgds

    Hi Nagraj
    As of your suggestion, I have re-written the query as below:
    * Declarations
    TYPES: BEGIN OF TYP_COLL_ORD,
            VBELN  LIKE VBAK-VBELN,
            POSNR  LIKE VBUP-POSNR,
            MATNR  LIKE VBAP-MATNR,
            KWMENG LIKE VBAP-KWMENG,
            KBMENG LIKE VBAP-KBMENG,
            ERDAT  LIKE VBAK-ERDAT,
            ERZET  LIKE VBAK-ERZET,
            PSTYV  LIKE VBAP-PSTYV,
            AUART  LIKE VBAK-AUART, u201Calready exists in type
            ETTYP  LIKE VBEP-ETTYP,
            EDATU  LIKE VBEP-EDATU.
    TYPES: END OF TYP_COLL_ORD.
    DATA: INT_COLL_ORD TYPE TABLE OF TYP_COLL_ORD WITH HEADER LINE.
    TYPES: BEGIN OF TYP_VBUK,
            AUART  LIKE VBAK-AUART, u201Chave added this field
            VBELN  LIKE VBUK-VBELN,
            UVALL  LIKE VBUK-UVALL,
            CMGST  LIKE VBUK-CMGST.
    TYPES: END OF TYP_VBUK.
    DATA: INT_VBUK TYPE TABLE OF TYP_VBUK WITH HEADER LINE.
    *QUERY#1 u2013 for VBAK & VBUK Join
    SELECT A~AUART B~VBELN B~UVALL B~CMGST
    INTO TABLE INT_VBUK
    FROM VBAK AS A INNER JOIN VBUK AS B
    ON A~VBELN EQ B~VBELN
    WHERE A~VBELN IN s_VBELN AND
    A~auart in s_auart AND
    A~vkorg in s_vkorg AND
    A~vbtyp eq 'C' AND
    B~UVALL NE 'A'.
    IF NOT INT_VBUK[] IS INITIAL.
    SORT INT_VBUK BY VBELN.
    DELETE ADJACENT DUPLICATES FROM INT_VBUK COMPARING VBELN.
    *QUERY#2 u2013 for VBAP & VBEP Join
    SELECT A~VBELN A~POSNR A~MATNR A~KWMENG A~KBMENG A~ERDAT A~ERZET A~PSTYV B~ETTYP B~EDATU
    INTO TABLE INT_COLL_ORD
    FROM VBAP AS A INNER JOIN VBEP AS B
    ON B~VBELN EQ A~VBELN AND B~POSNR EQ A~POSNR AND B~MANDT EQ A~MANDT
    FOR ALL ENTRIES IN INT_VBUK
    WHERE A~VBELN = INT_VBUK-VBELN AND
    ( ( matnr LIKE c_prefix_sp AND zz_msposnr NE 0 AND kbmeng EQ 0 )
    OR ( matnr LIKE c_prefix_fp AND kwmeng NE A~kbmeng ) ) AND
    A~ABGRU EQ SPACE AND
    A~MTVFP IN R_MTVFP AND
    A~PRCTR IN R_PRCT AND
    B~ETENR EQ '1'.
    ENDIF.
      SORT INT_COLL_ORD BY  VBELN POSNR ETTYP.
      DELETE ADJACENT DUPLICATES FROM INT_COLL_ORD
        COMPARING VBELN POSNR.
      CHECK NOT INT_COLL_ORD[] IS INITIAL.
      LOOP AT INT_COLL_ORD.
        CLEAR: L_MTART,L_ATPPR,L_ETTYP.
        IF L_PREVIOUS_ETTYP NE INT_COLL_ORD-ETTYP OR
          L_PREVIOUS_AUART NE INT_COLL_ORD-AUART.
          READ TABLE INT_OVRCTL WITH KEY AUART = INT_COLL_ORD-AUART ETTYP = INT_COLL_ORD-ETTYP.
          CHECK SY-SUBRC NE 0.
    Now, the issue is:
    Please note that declaration for INT_COLL_ORD has a field AUART, which is used in further parts of program (see the statement just above)
    But, since neither VBAP nor VBEP contains AUART field, it cannot be fetched through the QUERY#2. So this value is not populated into INT_COLL_ORD through SELECT Query.
    Since this field is used in later part of program & that the internal table has no value for this field, it dumps!!
    How to include this value into the INT_COLL_ORD?
    Plz suggest....

  • How to write the select query with complex where condition

    Hi all,
    Can u help me in writing  following select query.
    select * from zu1cd_corr where time_stamp between firstday and lastday .
    In the above query time_stamp contains the date and time.
    where as firstday and lastday contains the dates.
    I need to compare the date in the time_stamp with the firstday and lastday.
    But time_stamp contains the time also and it is char of 14 characters length.

    Hi,
    If that is the case u can do as advait specified....
    if the firstday and secondday are select-options then declare two more variables having 14 character length and then concatenate '000000' to firstday variable and '240000' to last day variable and then write ur query.
    CLEAR : lv_firstday,
                 lv_lastday.
    concatenate firstday '000000' to lv_firstday.
    concatenate lastday '240000' to lv_lastday.
    ranges : r_Date for zu1cd_corr-time_stamp.
    r_date-sign = 'I'.
    r_date-option = 'BT'.
    r_Date-low = lv_firstday.
    r_Date-high = lv_lastday.
    append r_date.
    select * from zu1cd_corr  into table it_zu1cd_corr where time_stamp in  r_Date.
    I hope it helps.
    Regards,
    Nagaraj

  • Select query using variable

    Hi all,
    If I have a variable with multiple value (returned from bulk collect), how can I pass it into a select query as a condition?
    Eg.
    set serveroutput on
    declare
    type v_LockSessInfo is table of integer;
    empdata v_LockSessInfo;
    begin
    select unique sid bulk collect into empdata from v$lock;
    [select sid,serial#,username from v$session where sid in (empdata)]
    end;
    I hope to be able to pass in the variable collected, into the next select statement. How can I achieve it?
    Thanks in advance.
    Eugene

    Sorry for any confusion caused, I have almost 0 knowledge on pl/sql, only can survie on normal sql query.
    Further elaboration, the intention of my query is to query out any locking that exists in my DB. It meant to serve as a report to management, so I have to break it down into couple of sections for easier reference (minimising the complication that may arise from others who view the report).
    Couple of steps/procedures I am thinking of:
    1) query out the unique sid that exists in v$lock (blocking and blocked sessions) <<< this set of returned record (SIDs) should be stored in a variable.
    Eg. achived by the select statement "select unique sid from v$lock into [variable]"
    2) query v$sessions for the lock details from step 1's output. Username, sid, serial#, machine etc.
    Eg. To be achieved by "select sid,serial#...... from v$session where sid in [variable]; Same condition applies to 2 and 3.
    3) query v$locked_object to identify which are the blocking/blocked sessions, and who's blocking who from step 1's output.
    4) query the locked object and locked record (based on rowid locked) from step 1's output.
    This is all that I can think of at the moment. Any opinions that can perform the above activity will be appreciated alot. Hope I'm able to clear up any confusion triggered.
    PS: I can't re-query the SID as the SID may change or be lost upon the re-query therefore losing any evident. Thus I was thinking of putting it into a variable for consistent querying for step 2,3 and 4. All 4 steps will be performed within a single script.
    Regards
    Eugene
    Edited by: eteo78 on May 28, 2009 8:40 AM

  • Select Query with Inner Join

    Dear Experts,
    I have writen a inner join code with MKPF and MSEG which taking too much time, while I have used index.
    Indexes are:
    MSEG
    MATNR
    WERKS
    LGORT
    BWART
    SOBKZ
    MKPF
    BUDAT
    MBLNR
    My Select Query is :
      SELECT B~MATNR
                   B~MAT_KDAUF
                   B~MAT_KDPOS
                   B~BWART
                   B~MENGE
                   B~MEINS
                   B~AUFNR
        INTO TABLE IT_MSEG
        FROM MKPF AS A
          INNER JOIN MSEG AS B
             ON AMBLNR EQ BMBLNR
            AND AMJAHR EQ BMJAHR
        WHERE A~BUDAT IN BUDAT
          AND B~MATNR IN MATNR
          AND B~WERKS IN WERKS
          AND B~LGORT IN LGORT
          AND B~BWART IN BWART.

    hi,
    you can use  for all entries  it will work faster then joins
    About it:*
    FOR ALL ENTRIES WHERE
    Syntax
    ... FOR ALL ENTRIES IN itab WHERE ... col operator itab-comp ...
    Effect
    If the addition FOR ALL ENTRIES is specified before the language element WHERE, then the components comp of the internal table itab can be used as operands when comparing with relational operators.
    The internal table itab must have a structured line type and the component comp must be compatible with the column col.
    The logical expression sql_cond of the WHERE condition can comprise various logical expressions by using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one Comparison with a column of the internal table itab, which can be specified either statistically or dynamically (Release 6.40 and higher). In a statement with a SELECTstatement with FOR ALL ENTRIES, the addition ORDER BY can only be used with the addition PRIMARY KEY.
    The whole logical expression sql_cond is evaluated for each individual line of the internal table itab. The resulting set of the SELECT statement is the union of the resulting sets from the individual evaluations. Duplicate lines are automatically removed from the resulting set. If the internal table itab is empty, the whole WHERE statement is ignored and all lines in the database are put in the resulting set.
    Notes
    In Release 6.10 and higher, the same internal table can be specified after FOR ALL ENTRIES and after INTO.
    The addition FOR ALL ENTRIES is only possible before WHERE conditions of the SELECT statement.
    Example
    Exporting all flight data for a specified departure city. The relevant airlines and flight numbers are first put in an internal table entry_tab, which is evaluated in the WHERE condition of the subsquent SELECT statement.
    PARAMETERS p_city TYPE spfli-cityfrom.
    TYPES: BEGIN OF entry_tab_type,
             carrid TYPE spfli-carrid,
             connid TYPE spfli-connid,
           END OF entry_tab_type.
    DATA: entry_tab   TYPE TABLE OF entry_tab_type,
          sflight_tab TYPE SORTED TABLE OF sflight
                           WITH UNIQUE KEY carrid connid fldate.
    SELECT carrid connid
           FROM spfli
           INTO CORRESPONDING FIELDS OF TABLE entry_tab
           WHERE cityfrom = p_city.
    SELECT carrid connid fldate
           FROM sflight
           INTO CORRESPONDING FIELDS OF TABLE sflight_tab
           FOR ALL ENTRIES IN entry_tab
           WHERE carrid = entry_tab-carrid AND
                 connid = entry_tab-connid.
    hope it will help you
    Rahul sharma
    Edited by: RAHUL SHARMA on Sep 11, 2008 8:10 AM

  • Select query with o/p

    Hi,
    I have one table test_tab with column names empno,empname.The test_tab values is as follows,
    empno empname
    01 siva
    02 ram
    03 kamal
    04 sathish
    i will give the empname values like 'siva','roshan',but in the table roshan name is not there in my table.I need the below mentioned o/p
    example qry: select empno,empname from test_tab where empname in('siva','roshan');
    my o/p should be like this,
    empname empno
    siva 01
    roshan ''
    But the empname 'roshan' is not there in table.I need the empname as 'roshan' and empno is null value in a single select query or subquery or any sql statements.
    Please help me the resolve this issue.
    Thanks
    Sivaraman

    kn_sivaraman wrote:
    Hi,
    Yes,we will see performance issue later.Now we want put where clause in this query like empno >'03'.Suppose we will pass values like 'kamal,roshan,sathish'
    example qry: select empno,empname from test_tab where empname in('kamal','roshan','sathish') and empno>03;
    my o/p should be like this,
    empname empno
    sathish 04
    roshan ''
    For the current query we will get the all three values.Please help this issue.
    Thanks
    SivaThat logic doesn't make sense.
    You're original requirement was to get all those names you passed in and just show a blank empno if they weren't in the table.
    Now you're adding a condition that restricts what is seen in the table, so of course you will still get all 3 values you pass, just that "kamal" is not seen as being in the table so becomes part of the original requirement to show those passed in without their empno.
    I can only guess you're wanting to just restrict the overall output, in which case you need to put the restriction outside the join but still cater for null empno's...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (-- comma seperated input values
      2             select 'kamal,roshan,sathish' as names from dual
      3            )
      4      ,s as (-- split the names into rows
      5             select regexp_substr(names, '[^,]+', 1, level) as nm
      6             from   t
      7             connect by regexp_substr(names, '[^,]+', 1, level) is not null
      8            )
      9  -- now outer join the names to the data
    10  select s.nm as empname
    11        ,test_tab.empno
    12  from   s left outer join test_tab on (s.nm = test_tab.empname)
    13* where to_number(test_tab.empno) > 3 or test_tab.empno is null
    SQL> /
    EMPNAME              EM
    sathish              04
    roshan

  • Copy function based on the query with variables

    Hello
    Let me share the scenario I need to implement. I have a planning query with layout like shop / material / sales volume. The variables are shop number and calendar month. User opens the planning query, selects shop number and month, then sees the list of materials and puts the planned sales volume, then saves as a temporary version. Saving as a temporary version is realized by standard u201Csaveu201D function. The matter is that the user needs to have a possibility to copy this version to official one. I created the button and linked it with the copy function. The problem is that when a user clicks this button, the function asks him/her to provide variables again. I would like to have the button which copies the data with the same selection criteria as the query already has.
    Any idea?
    Arelis.

    Hi,
    I think when you add the button you specify the planning sequence name and that takes the filter of the modeler .Now when you try to call the planning sequence the filter variables are also added to the button as VAR_NAME, VAR_VALUE which prompts you for the variable again.Delete VAR_NAME,VAR_VALUE at the back of the button  manually and then save your work book.Then it will not ask for variable entry and the values that you have specified in the query filter will pass on to modeler filters.As variables are global.
    Similarly if you are using planning function then at the back of the button remove the VAR_NAME,VAR_VALUE.
    Hope this may help.
    Regards,
    Indu

  • Select query with secondary index

    hi,
    i have a report which is giving performance issues on a perticular select query on KONH table.
    the select query doesnt use the primary key fields and table already has around 19 million entries.So there was a secondary index created for the fields in the table.
    now, KONH is a client specific table, and hence has MANDT as the first field. when the table is not indexed it is sorted according to the order of fields, like first MANDT, then primary key fields and then remaining fields.. (correct me if i am wrong)
    but the secondary index created doesnt has MANDT in it..(yea, a mistake! )...
    but instead of correccting the secondary index, i am told to change the select query..
    so, i used a "client specific" syntax to sort the issue.. but i dont understand whre i should put the "where mandt eq sy-mandt" clause..
    should i put it right after all my secondary index fields are over? or what happens to the order of fields which are not present in the list of secondary index?
    kindaly help.
    thanx.

    Hi chinmay kulkarni,
    its better if you can ask concerned person to add MANDT field in your  index as well....
    Indexes and MANDT
    If a table begins with the mandt field, so should its indexes. If a table begins with mandt and an index doesn't, the optimizer might not use the index.
    Remember, if you will, Open SQL's automatic client handling feature. When select * from ztxlfa1 where land1 = 'US' is executed, the actual SQL sent to the database is select * from ztxlfa1 where mandt = sy-mandt and land1 = 'US'. Sy-mandt contains the current logon client. When you select rows from a table using Open SQL, the system automatically adds sy-mandt to the where clause, which causes only those rows pertaining to the current logon client to be found.
    When you create an index on a table containing mandt, therefore, you should also include mandt in the index. It should come first in the index, because it will always appear first in the generated SQL.
    Index: Technical key of a database table.
    Primary index: The primary index contains the key fields of the table and a pointer to the non-key fields of the table. The primary index is created automatically when the table is created in the database.
    Secondary index: Additional indexes could be created considering the most frequently accessed dimensions of the table.
    Structure of an Index
    An index can be used to speed up the selection of data records from a table.
    An index can be considered to be a copy of a database table reduced to certain fields. The data is stored in sorted form in this copy. This sorting permits fast access to the records of the table (for example using a binary search). Not all of the fields of the table are contained in the index. The index also contains a pointer from the index entry to the corresponding table entry to permit all the field contents to be read.
    When creating indexes, please note that:
    An index can only be used up to the last specified field in the selection! The fields which are specified in the WHERE clause for a large number of selections should be in the first position.
    Only those fields whose values significantly restrict the amount of data are meaningful in an index.
    When you change a data record of a table, you must adjust the index sorting. Tables whose contents are frequently changed therefore should not have too many indexes.
    Make sure that the indexes on a table are as disjunctive as possible.
    (That is they should contain as few fields in common as possible. If two indexes on a table have a large number of common fields, this could make it more difficult for the optimizer to choose the most selective index.)
    For Example...
    SELECT KUNNR KUNN2 INTO TABLE T_CUST_TERR
    FROM KNVP CLIENT SPECIFIED
    WHERE MANDT = SY-MANDT " here MANDT shd be first
    AND KUNN2 IN S_TERR
    AND PARVW LIKE 'Z%'.
    Accessing tables using Indexes
    The database optimizer decides which index on the table should be used by the database to access data records.
    You must distinguish between the primary index and secondary indexes of a table. The primary index contains the key fields of the table. The primary index is automatically created in the database when the table is activated. If a large table is frequently accessed such that it is not possible to apply primary index sorting, you should create secondary indexes for the table.
    The indexes on a table have a three-character index ID. '0' is reserved for the primary index. Customers can create their own indexes on SAP tables; their IDs must begin with Y or Z.
    If the index fields have key function, i.e. they already uniquely identify each record of the table, an index can be called a unique index. This ensures that there are no duplicate index fields in the database.
    When you define a secondary index in the ABAP Dictionary, you can specify whether it should be created on the database when it is activated. Some indexes only result in a gain in performance for certain database systems. You can therefore specify a list of database systems when you define an index. The index is then only created on the specified database systems when activated
    Also pls have a look on below link
    http://www.sapfans.com/sapfans/forum/devel/messages/30240.html
    Hope it will solve your problem..
    Reward points if useful...
    Thanks & Regards
    ilesh 24x7

  • Select query with UNION clause in database adapter

    Friends,
    I have got a SQL query with two UNION clause withing it. like
    select a,b,c
    from a
    union
    select a,b,c
    from b
    The schema generated is like below in sequence
    <element>a</element>
    <element>b</element>
    <element>c</element>
    <element>a</element>
    <element>b</element>
    <element>c</element>
    So, the columns from different select queries joined with UNION clause are all appeared in schema instead of the distinct columns.
    Is there any way around to solve this issue ? or will need to with DB function/procedure.

    I think I know what you are saying but your example doesn't make sense, your SQL should produce something like
    I had to change a, b, c with elementA, elementB, elementC as a and b are reserved html tags.
    <elementA>DateA</elementA>
    <elementB>DataB</elementB>
    <elementC>DataC</elementC>
    ...What is the result of the query when you run it in SQLPlus? Is it what you expect?
    cheers
    James

Maybe you are looking for

  • Mac Mini not recognizing USB optical drive - when Windows 7 in the drive

    This is a really strange situation. I purchased a DVD writer in order to install Windows 7 on my Mac Mini (the SuperDrive stopped functioning some time ago). I've been able to boot from this optical drive to install Snow Leopard, but the Win7 disk is

  • Section Header Text Background Color

    Hi have a catalog that has a running section header that will be placed over a black graphic the width of the page header.  I would like to have a white background box appear the length of the header section text, but not be the full length of the te

  • Gallery not opening...tried everything.

    Called the Samsung help line and the person I dealt with had no idea how to help. I only have a few apps and a couple pictures. I also have a 16 gig simcard so not enough room isn't the issue. My only guess is the phone either stopped seeing the simc

  • VV501 error in Posting Goods Issue (VL02N)

    Hi, in VL02N when we try to "Post Goods Issue" sap gives the error "vv501 - Blocking error" The error is like below: Diagnosis A system error occured during the attempt to block the material you are processing. System Response It can be assumed that

  • Pass multiple rows from sp to calling prog

    I have a stored procedure using cursor to get multiple rows from the db, how can I pass these rows to the calling prog? Is the out variable returns the last row only? This is what I did: Create or replace procedure mysp ( var1 in number, var2 OUT num