Select query where codn

Hi in my requirement in a select query i have to place a where codn using asset value date.Actually the asset value date has from date and end date.The from date is present in a table and end date is present in another table so now how to put the where codn.Please give some suggestions.

Hi hema,
Use subquery as follows;
Select.....
.....Where asset_date BETWEEN (Select single asset_fromdate from fromdate_table where key_field = value) AND (Select single asset_todate from todate_table where key_field = value)
Hope this helps you...
Regards
Karthik D

Similar Messages

  • Slow Select Query - Where clause contains Seconday index field +other flds

    Hi friends,
    The below query is taking about an Hour to execute in production server when there are about 6 Million records in PLAF table. I have verified the trace in ST05 and the correct secondary index (Material Matnr + Plant Plwrk) is being selected.
    SELECT plnum
                 matnr
                 plwrk
                 pedtr
                 dispo
                 rsnum  FROM  plaf
                INTO TABLE it_orders
                WHERE ( ( matnr  IN r_mat1 )  OR
                                 matnr IN r_mat2  AND dispo IN s_mrp1 ) AND
                 pedtr IN s_date AND   
                 obart = '1'.
    Will it be a good idea to have only MATNR (secondary index field) in the where condition of the select query and delete the internal table entries for the other where conditions ?
    Edited by: Shruthi Seth on Feb 1, 2009 10:10 AM

    Hello.
    Creating a range r_mat = r_mat1 + r_mat2, I would do something like:
    READ TABLE s_mrp1 TRANSPORTING NO FIELDS INDEX 1.
    IF sy-subrc EQ 0.
      SELECT plnum matnr plwrk pedtr dispo rsnum
        FROM plaf
        INTO wa_orders
       WHERE matnr IN r_mat
         AND pedtr IN s_date
         AND obart = '1'.
        IF wa_orders-matnr IN r_mat2.
          CHECK wa_orders-dispo IN s_mrp1.
        ENDIF.
        APPEND wa_orders TO it_orders.
      ENDSELECT.
    ELSE.
      SELECT plnum matnr plwrk pedtr dispo rsnum
        FROM plaf
        INTO TABLE it_orders
       WHERE matnr IN r_mat1
         AND pedtr IN s_date
         AND obart = '1'.
    ENDIF.
    Regards,
    Valter Oliveira.

  • Select Query where multiple col1+col2 in ('value1','value2','value3')

    hello,
    i've table :
    month year .. other columns
    1 2012
    2 2012
    1 2013
    2 2013
    1 2014
    2 2014
    I've multi select filter years, then months of these years as
    1-year checkcombobox - all available years on the table. ex(2012,2013..)
    2-month checkcombobox - all months for selected years above. ex(1-2013,2-2013..)
    i want to select from my table where month & year = selected month & year. 
    i used to do it like this : but i think i've problem with performance with this solution:
    i use stored procedure with @monthyear nvarchar(max) parameter of selected months and year as text like '1-2012,2-2012,6-2013'
    -i use 'uf_ParseDelimitedString2' function to extract above string into table of string.
    the query:
    select from mytable where convert(nvarchar(10),mytable.month) + '-' + convert(nvarchar(10),mytable.year) in (select string from uf_ParseDelimitedString2(@monthyear))
    -function i used on above query to Parse Delimited String and return table of string.
    ALTER FUNCTION [dbo].[uf_ParseDelimitedString2](@strToParse VARCHAR(MAX)) RETURNS @tblStrToParse TABLE
    (string nvarchar(max))
    AS
    BEGIN
    DECLARE @pos int
    DECLARE @piece nvarchar(max)
    -- Need to tack a delimiter onto the end of the input string if one doesn't exist
    IF RIGHT(RTRIM(@strToParse),1) <> ','
    SET @strToParse = @strToParse + ','
    SET @pos = PATINDEX('%,%' , @strToParse)
    WHILE @pos <> 0
    BEGIN
    SET @piece = left(@strToParse, @pos - 1)
    -- You have a piece of data, so insert it, print it, do whatever you want to with it.
    INSERT INTO @tblStrToParse VALUES(@piece)
    SET @strToParse = STUFF(@strToParse, 1, @pos, '')
    SET @pos = patindex('%,%' , @strToParse)
    END
    RETURN
    END
    thank your in advance ..

    hi.. 
    review this after i created a function:
    create FUNCTION [dbo].[uf_ParseDelimitedString2Col](@t VARCHAR(MAX))
    RETURNS @tblStrToParse TABLE
    ([1] int ,[2] int)
    AS
    BEGIN
    insert into @tblStrToParse
    SELECT [1], [2]
    FROM (
    SELECT
    t2.id
    , t2.name
    , rn2 = ROW_NUMBER() OVER (PARTITION BY t2.id ORDER BY 1/0)
    FROM (
    SELECT
    id = t.c.value('@n', 'INT')
    , name = t.c.value('@s', 'nvarchar(20)')
    FROM (
    SELECT x = CAST('<t s = "' +
    REPLACE(token + '-', '-', '" n = "' + CAST(rn AS VARCHAR(10))
    + '" /><t s = "') + '" />' AS XML)
    FROM (
    SELECT
    token = t.c.value('.', 'VARCHAR(100)')
    , rn = ROW_NUMBER() OVER (ORDER BY 1/0)
    FROM (
    SELECT x = CAST('<t>' + REPLACE(@t, ',', '</t><t>') + '</t>' AS XML)
    ) r
    CROSS APPLY x.nodes('/t') t(c)
    ) t
    ) d
    CROSS APPLY x.nodes('/t') t(c)
    ) t2
    WHERE t2.name != ''
    ) t3
    PIVOT (
    MAX(name) FOR rn2 IN ([1], [2])
    ) p
    Return
    END
    then 
    i used this code.. 
    select * from mytable st cross apply dbo.uf_ParseDelimitedString2Col('1-2014,3-2014') x where st.month = x.[1] and st.year = x.[2]
    how about that..
    thank you.

  • Select Query where multiple column in multiple values (cant use in clause)

    I can use (in clause) with on column like this:
    Select code from table where code in(1,2,3)
    -------------------------------My case:-------------------------------------------------
    I’ve 4 columns PK of table as below 
    I need to :
    select
    where (code, month, year) in ((1,1,2013) and (2,1,2014) and (2,2,2015))
    i can't write it this way :
    select where code in (1,2) and month in (1,2) and year in (2013,2014,2015)
    case i'll get my rows but others included like (1,1,2015) , (1,1,2014),(2,1,2013) .. etc
    I’m terribly want to solve this problem
    Please help me
    Code (pk)
    Month (pk)
    Year (pk)
    emp_code(pk)
    1
    1
    2013
    101
    1
    1
    2013
    102
    2
    1
    2013
    101
    2
    1
    2013
    102
    1
    2
    2013
    101
    1
    2
    2013
    102
    2
    2
    2013
    101
    2
    2
    2013
    102
    1
    1
    2014
    101
    1
    1
    2014
    102
    2
    1
    2014
    101
    2
    1
    2014
    102
    1
    2
    2014
    101
    1
    2
    2014
    102
    2
    2
    2014
    101
    2
    2
    2014
    102
    1
    1
    2015
    101
    1
    1
    2015
    102
    2
    1
    2015
    101
    2
    1
    2015
    102
    1
    2
    2015
    101
    1
    2
    2015
    102
    2
    2
    2015
    101
    2
    2
    2015
    102
    thank you

    In T-SQL you have to use OR-ed predicates. 
    In full ANSI Standard SQL youcan write row comparisons  (a,b,c) = (1,2,3) etc! but not in T-SQL dialect. Ignoring that problem, what you have is a design flaw called attribute splitting; you have put one unit of measurement
    in two columns. 
     I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the
    ISO-8601 data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • URGENT: To change the where condition in select query at runtime ?

    Hi,
    I have to develop a report, 4 which I have created a selection screen with 7 Input Parameters whose value is to be filled by the user while executing the report.
    On the basis of this I do the desired selection of output.
    But the problem is that how do I write my select Query(where condition) if the user enetrs only 2 Input parameters or 3 or whatever he feels like.
    Pls help me out...

    hi,
    check this sample code.
    Here i am populating where condition at runtime.
    DATA: V_WHERE TYPE STRING.
    SELECTION-SCREEN BEGIN OF BLOCK INPUT WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN,
                     S_ERDAT FOR VBAK-ERDAT.
    SELECTION-SCREEN END OF BLOCK INPUT.
    START-OF-SELECTION.
      PERFORM POPULATE_WHERE.
      PERFORM GET_VBAK_DATA.
    *&      Form  POPULATE_WHERE
    *       Populate Where
    FORM POPULATE_WHERE .
      IF NOT S_ERDAT[] IS INITIAL.
        CONCATENATE 'VBELN IN S_VBELN'
                    'AND'
                    'ERDAT IN S_ERDAT'
              INTO V_WHERE
              SEPARATED BY SPACE.
      ELSE.
        V_WHERE = 'VBELN IN S_VBELN'.
      ENDIF.
    ENDFORM.                    " POPULATE_WHERE
    *&      Form  GET_VBAK_DATA
    *       GET VBAK DATA
    FORM GET_VBAK_DATA .
      SELECT VBELN
             ERDAT
             VBTYP
             NETWR
             WAERK
             VKORG
             VTWEG
             SPART
        INTO CORRESPONDING FIELDS OF TABLE IT_VBAK
        FROM VBAK
        WHERE VBELN IN S_VBELN
        AND   ERDAT IN S_ERDAT.
       WHERE (V_WHERE).
    endform.
    Regards
    Sailaja.

  • Problem in select query in QUERY INFOSET

    Hi All
    I have requirement to find the sales text maintained for sales order in mass in production. By using the FM READ_TEXT i can pass the necessary values to get the sales text. We dont want to write a program and then transprot to P01. So what i did in SQ02 i create a infoset and worte code in the infoset. Here i am facing the problem that in the select query where clause what ever  on the selection screen values, for that the query need to fetch the records. But selection screen is dymically selected based on SQVI t-code.
    In select query if i write like this
    SELECT TDOBJECT TDNAME TDID TDSPRAS
           FROM STXH
           INTO TABLE IT_TEXT_DETAIL
           WHERE TDOBJECT     EQ C_KNMT .
    Here i have hardcoded KNMT so it will fetch only that value irrespective of any values on the selection screen. How to get the values based on the selection screen. I debugged the query it automatically generates the code for selection screen which i am not able to pass in the program.
    SAP has generated this code
    select-options SP$00004 for STXH-TDOBJECT.
    select-options SP$00005 for STXH-TDNAME.
    select-options SP$00006 for STXH-TDID.
      If i pass SP$00004 on where clause its giving me error. So how to pass it dynamically. Waiting for experts answer.
    Regards
    Vijay

    Hi Vijay,
    In this case concatenate 'TDOBJECT' 'EQ' C_KNMT INTO V_WHERE (Say) SEPERATED BY SPACE.
    DATA : v_where(90) type c.
    clear v_where.
    CONCATENATE  'TDOBJECT'
                               'EQ'
                               C_KNMT
                               INTO V_WHERE
                               SEPERATED BY SPACE.
    SELECT TDOBJECT TDNAME TDID TDSPRAS
           FROM STXH
           INTO TABLE IT_TEXT_DETAIL
           WHERE (V_WHERE) .
    Try to do this and let me know in case of any.
    Regards,
    SRinivas

  • Dynamic From statement in select query and/or outer join not working

    Dear Experts, I have a select query where the select columns are dynamic, the where condition is also dynamic. It is of the below format:
    Select (dynamic columns) INTO <wa>
    FROM a inner join b on af1 = bf1
    inner join c on af2 = cf2......
    WHERE (dynamic conditios)
    ORDER BY ( dynamic sort condition).
    Now I have to include some tables (dynamically depending on the user input) in the inner join statement which will give description for the selected fields. And these database tables may or may no be empty. So in this case, my select query will not return any data if these tables are empty. And I dont want that.
    I tried using outer join for the extra tables but it gave me a runtime error. I also tried forming the inner join statement dynamically but it was not supporting.
    Kindly give me pointers.
    Thanks

    Hey thanks for the reply, but the problem is not solved.
    I am already using  ( fileds, value) like table in my where condition and the select statement was working properly.
    the problem is that now I have to include some tables in the join statement which can be empty and so i want to use Outer join.
    But I am getting a runtime error as below:
    Error analysis
        An exception occurred that is explained in detail below.
        The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SYNTAX', was not
         caught in
        procedure "ZATSCSNG_RFC_READ_TABLE" "(FUNCTION)", nor was it propagated by a
         RAISING clause.
        Since the caller of the procedure could not have anticipated that the
        exception would occur, the current program is terminated.
        The reason for the exception is:
        The running ABAP program wanted to execute a SELECT statement whose
        WHERE condition was (partly) specified dynamically. The part that is
        specified in an internal table at runtime is compared to a field of the
        right table of an LEFT OUTER JOIN. Such comparisons are not supported by
         all database systems and are therefore not allowed.

  • Varray in the select query

    Hi ,
    Can we write a select query where we can pass varray in the where condition.
    I have this query in my stored procedure.
    eg :
    SELECT * from emp
         WHERE deptno in l_data1;
    where l_data is varray of type varchar2(40) where I have all the deptno in l_data.
    Thanks.

    This is business requirement.
    Here is my code.
    create or replace PROCEDURE getAttribute (p_product_model varchar2)
    AS
    l_data pattern_str_type := pattern_str_type();
    l_count NUMBER;
    l_child_name VARCHAR2(200);
    l_product_model VARCHAR2(40);
    l_data1 getAttrforModel := getAttrforModel();
    i NUMBER;
    BEGIN
    i := 1;
    l_data :=getattr();
    for i in 1 .. l_data.count loop
    l_data.extend;
    l_data1.extend;
    if(l_data(i).child_type = 'Attribute' and l_data(i).product_model_name <> p_product_model)THEN
    l_data1(i):=l_data(i).child_name;
    dbms_output.put_line(l_data1(i));
    END If;
    end loop;
    SELECT count(*) into l_count from
         WOC_ATTRIBUTE_CATEGORY WHERE category_name = 'Software' and Attribute_Name in l_data1;
    EXCEPTION
    WHEN OTHERS THEN
    RAISE;
    END ;
    CREATE OR REPLACE FUNCTION getAttr RETURN pattern_str_type
    IS
    l_data pattern_str_type := pattern_str_type();
    l_count NUMBER;
    l_child_name VARCHAR2(200);
    l_product_model VARCHAR2(40);
    i NUMBER;
    cursor getattr IS select child_name,child_type, product_model_name from woc_pattern_Structure;
    BEGIN
    i := 1;
    for rec in getattr loop
    l_data.extend;
    l_data(i) := temp_table(rec.child_name,rec.child_type,rec.product_model_name);
    --dbms_output.put_line(l_data(i).child_name||' '||l_data(i).child_type||' '||l_data(i).product_model_name);
    i := i + 1;
    end loop;
    RETURN l_data;
    EXCEPTION
    WHEN OTHERS THEN
    RAISE;
    END ;

  • Regarding select query Issue

    Hi ABAPERS,
          I had written one written one 'select single' query to retrieve the data from PRPS table.
    but what the data was selecting for OBJNR (Object number)field based on PSPNR(WBS element) .
    That OBJNR values in the report is totally different from the database table OBJNR  values.How its possible
    I am not getting.So can anyone please help me regarding this...
    Thanks and Regards
    Deepa

    Hi deepa,
    Pass the values to the select query where clause as you can see the values in SE16 display.(This is external format)
    If a table field as conversion routine, then SAP dosplay some thing on screen and store some thing else in data base.
    To check conversion exit go to domain of that field. Here you can see the routine used.
    For example you can check domain MATNR. Externally it display with leading zeros. But internally it stores with out zeros.
    Thanks,
    Vinod.

  • How to improve performance of select query when primary key is not referred

    Hi,
    There is a select query where we are unable to refrence primary key of the tables:
    Since, the the below code is refrensing to vgbel and vgpos fields instead of vbeln and posnr..... the performance is very  slow.
    select vbeln posnr into (wa-vbeln1, wa-posnr1)             
           from lips                                            
           where ( pstyv ne 'ZBAT'    
               and pstyv ne 'ZNLN' )  
               and vgbel = i_vbap-vbeln                         
               and vgpos = i_vbap-posnr.                        
    endselect.                                                 
    Please le t me know if you have some tips..

    hi,
    I hope you are using the select statement inside a loop ...endloop get that outside to improve the performance ..
    if not i_vbap[] is initial.
    select vbeln posnr into table it_lips
    from lips
    for all entries in  i_vbap
    where ( pstyv ne 'ZBAT'
    and pstyv ne 'ZNLN' )
    and vgbel = i_vbap-vbeln
    and vgpos = i_vbap-posnr.
    endif.

  • 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

  • Multiple values in where clause(IN) of select query in Cisco Cloud Portal using single field

    I can actually pass multiple values in the IN statement of select query using multiple dictionary fields in the data retrieval rule of the AFC in Cisco cloud portal like
    #dictionary.field1# = 1 and
    #dictionary.field2#=2
    select col1,col2 from table1 where col3 in (#dictionary.field1#,dictionary.field2#).
    but I want to pass mutiple values in a single field as
    #dictionary.field1#=1,2
    select col1,col2 from table1 where col3 in (#dictionary.field1#) and the query gives no data because it is taking as '1,2' instead of '1','2'.
    Please give the solution for passing multiple values in a single variable to use in IN operator of WHERE clause

    Ok, I now understand what you are trying to do. Unfortunately, you cannot inject parts of a SQL statement into a DDR through a dictionary field, which always represents a specific value (the comma in your case is attempting injection of a SQL construct to refer to multiple values). One possible solution is to arbitrarily consolidate your list of values using a delimiter that you know will not be in the values themselves such as a colon (:). Let's use 3 values as it serves as a better example.
    Set your dictionary field to a single reference to all 3 values of interest, say 'a', 'b', 'c' as:
    :a:b:c:  (you can use javascript to create this consolidated dictionary field)
    Now your query would look something like the following:
    select col1,col2 from table1 where #dictionary.field1t# like '%:'+col3+':%'
    This should achieve the desired result.

  • How to use string operation in where clause of select query

    Hello All,
    I just want to know how can i write a restriction in select query saying retrive data only begins with name "DE*".
    Explaination: If my table has records and names starts with character then i want to write a query to fetch all the records in which names starts with DE*.
    Thanks in advance for your quick reply...
    Dev.

    Hi
    In the where clause you need to write like
    WHERE NAME LIKE 'DE%'
    Regards
    Sudheer

  • In Select query how to fetch values through multiple parameters  where conditon

    Dear Experts,
    I have one table(T) with 4 fields: f1, f2, f3, f4. In that based on f2, f3, f4 and parameter condition( f2 values) how to fetch f1 values. I have attached screen shot. What is the where condition in select query?
    DATA: it_T type standard table of ty_T,
              wa_T type ty_T.
    parameters: p_f2_1 type T-f3,
                      p_f2_2 type T-f3,
                      p_f2_3 type T-f3,
                      p_f2_4 type T-f4,
                      p_f2_5 type T-f4,
                      p_f2_6 type T-f4.
    select f1  f2  f3  f4 from T into table it_T where ?
    What is the where condition ?.
    Regards,
    Abbas.

    Hi Syed,
    Do all the parameters p_f2_1 ... p_f2_6 contain values for the same field f2? And do you need all the entries from the table T which contain f2 = any of the entered value? If yes, Then you can try the following where condition -
    select f1  f2  f3  f4 from T into table it_T
      where f2 =  p_f2_1  OR
                 f2 =  p_f2_2  OR
                 f2 =  p_f2_3  OR
                 f2 =  p_f2_4  OR
                 f2 =  p_f2_5  OR
                 f2 =  p_f2_6.
    P.S: If any of the above parameters are optional as per your requirement it will be better to build a dynamic query and use it in the where condition.
    Regards,
    Rachna.

  • Can we use concatenate in where clause of a select query

    I have a select query as follows....
        SELECT ebeln ebelp belnr vgabe bwart DMBTR
                                 FROM ekbe
                                 INTO TABLE i_ekbe
                                 FOR ALL ENTRIES IN i_blck
                                 WHERE ebeln =  i_blck-ebeln AND ebelp =                                                                               
    i_blck-ebelp.
    Now i want to retrieve data from BKPF ..can i write a select query something like....
    select * from BKPF into itab
                FOR ALL ENTRIES IN i_ekbe
                where awkey = ( conatenate i_ekbe-belnr i_ekbe-gjahr )
    OR ELSE...is there any other way to link table ekbe and bseg ???

    Hi Poonam,
    SELECT ebeln ebelp belnr vgabe bwart DMBTR
    FROM ekbe
    INTO TABLE i_ekbe
    FOR ALL ENTRIES IN i_blck
    WHERE ebeln = i_blck-ebeln
    AND ebelp = i_blck-ebelp.
    select *
    from BKPF
    into  table itab
    FOR ALL ENTRIES IN i_ekbe
    where belnr = i_ekbe-belnr.
    If u want to check with AWKEY concatenate into seperate field and then use to check in where condition.
    data: lw_awkey(20) type c.
    CONCATENATE  i_ekbe-belnr  i_ekbe-gjahr  INTO lw_awkey.
    select *
    from BKPF
    into  table itab
    FOR ALL ENTRIES IN i_ekbe
    where awkey = lw_awkey
    Best regards,
    raam

Maybe you are looking for

  • Unable to generate PDF file from reports

    Hi, After running the report when I tried to generate the output to pdf file, I see the number of pages being generated again, I dont see any file being created although it prompts for the file name. Any suggestions Thanks in Advance

  • Dynamic binding of items in sap.m.Table using JS views

    HI, I am developing a master detail page for a Purchase Order application. In master page, i display the list of Purchase Orders & on clicking the PO, i should display the detail page. We use different ODATA models for Master & detail page. I am able

  • Form6i-10g Migration-Look&Feel-Button lables are shrinked end with dot..ASP

    Hi All, We have migrated the forms 6i to forms 10g R2.We are facing push button issue like,the lable which is displayed in the button is reduced. Assume the button's label name is Cancel. Actully it is displaying like Can.....We have forms count near

  • 2x16 GB RAM instead of 4x8 RAM?

    I am planning to buy the new MacPro. I mainly do after effects and cinema 4d. I am confsued wheather to buy a 6 core or an 8 core CPU. Is it worth spending additional $1500 for 8 core? On the other note, in regrards to the future upgrades currently i

  • Z-Report Preparation

    Hi, I want to know basics in preparing the Z-Reports. I mean when you do confirmation where the data will be saved? the table name that appears in CO11N screen (by clicking F1-> Tech info) will remain same when we save? or will it change? any specifi