Between Clause in select query

In the selection screen, i enter April month i.e. 04. Now i have to go 5 months back i.e. November i.e. 11. Now from table T247, I want to select data from November to April. Ho do i do it.

Hi,
If you want you can also use BETWEEN clause in select condition.
Example :
DATA: LOW TYPE I VALUE '04',
           HIGH TYPE I VALUE '11.
SELECT FIELDS.....
FROM TABLE
INTO TABLE ITAB
WHERE PARAMETER BETWEEN LOW AND HIGH.
This will help you.
Plz reward if useful.
Thanks,
Dhanahsri.
Edited by: Dhanashri Pawar on Jun 18, 2008 11:52 AM
Edited by: Dhanashri Pawar on Jun 18, 2008 11:53 AM

Similar Messages

  • PROBLEM WITH MY DATE BETWEEN CLAUSE IN SELECT QUERY

    WHEN I RUN THE CODE IT'S FETCHING DATA FROM 2007,2008,2009.
    SELECT ERDAT VBELN NETWR
    FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_VBRK
    WHERE ERDAT BETWEEN '01.11.2008' AND '30.11.2008'.
    PLEASE GIVE ME A SOLUTION GUYS.

    Hi, Zubaer,
    Please Don't Use All Caps in Subject and Body Text too
    Have a look at [Rules of Engagement|https://www.sdn.sap.com/irj/scn/wiki?path=/display/home/rulesofEngagement]
    Under Heading
    - Use a Good Subject Line
    Do not use words in capital letters
    Use the following way. it will solve out your Problem,
    SELECT erdat vbeln netwr
    FROM vbrk INTO CORRESPONDING FIELDS OF TABLE it_vbrk
    WHERE erdat BETWEEN '20081101' AND '20081130'.
    Best Regards,
    Faisal

  • Regarding  dynamically assigning the where clause to select query

    hi,
      Please send the code regarding how to dynamically assign the where clause to select query.
    thanks in advance

    SELECT <fileds>
            INTO TABLE itab
            FROM dbase
            WHERE  condition.

  • 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

  • How to dynamically add field name in where clause of select query in web dynpro?

    Hello,
    Can any body tell me how i can use select query with dynamic wheere condition.
    i have a requirement like there are multiple input fields  and i want to select data from two database
    and condition may vary .

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

  • How to formulate where clause in select query at runtime..??

    I am facing a problem..
    I have to generate a select query during runtime..For Ex: when user selects a row in an alv report, particular date field is to be read and another report is to be opened for that data..
    I know how to make drill down report but my problem is concatenating  date field...
    Plz tell a solution....

    Hi,
    Try like this....
    refresh : gt_tvarvc_temp[].                                       
      gt_tvarvc_temp[] = lt_tvarvc[].                                   
          loop at gt_tvarvc_temp into gs_tvarvc_temp
                                  where name = 'CREDIT_MEMO_DOC_TYPE'.  
            r_blart-sign = gs_tvarvc_temp-sign.                         
            r_blart-option = gs_tvarvc_temp-opti.                      
            r_blart-low = gs_tvarvc_temp-low.                           
            append r_blart.                                            
            clear r_blart.                                             
          endloop.                                                     
          concatenate 'BLART IN ' 'r_blart' into lv_condition
          separated by space.
    if not lv_customer_cond is initial.
          if lv_condition is initial.
            concatenate lv_customer_cond lv_condition
                into lv_condition separated by space.
          else.
            concatenate lv_condition 'AND' lv_customer_cond
                into lv_condition separated by space.
          endif.
        endif.
    select bukrs belnr gjahr appending corresponding fields        
                                        of table lt_potential_credits
                                        from bsid
                                        where (lv_condition).
    Hope its helps

  • Dynamic where clause in select query

    Hi
    I'm trying for a dynamic query and in the dynamic where clause i'm checking a field for constant.....for instance if i wanna to use WERKS EQ '0478' how to declare it in dync where clause. i tried for the following:
    SELECT  (TAB_FIELD) INTO TABLE DITAB UP TO 10 ROWS FROM (TAB_NAME) WHERE (CONDI).
    heree CONDI = 'werks eq 0287'   . in this case the query fails as the werks shud be equal to '0287' and not just 0287. How to handle this? i tried for the following
    CONDI = 'werks eq " '0287' " ' but no luck as it is not a valid stmt as i knew.

    hi prabhu,
    this is how u select dynamically...
    DATA: COND(72) TYPE C,
    ITAB LIKE TABLE OF COND.
    PARAMETERS: CITY1(10) TYPE C, CITY2(10) TYPE C.
    DATA WA TYPE SPFLI-CITYFROM.
    CONCATENATE 'CITYFROM = ''' CITY1 '''' INTO COND.
    APPEND COND TO ITAB.
    CONCATENATE 'OR CITYFROM = ''' CITY2 '''' INTO COND.
    APPEND COND TO ITAB.
    CONCATENATE 'OR CITYFROM = ''' 'BERLIN' '''' INTO COND.
    APPEND COND TO ITAB.
    LOOP AT ITAB INTO COND.
    WRITE COND.
    ENDLOOP.
    SKIP.
    SELECT CITYFROM
    INTO WA
    FROM SPFLI
    WHERE (ITAB).
    WRITE / WA.
    ENDSELECT.
    regards,
    sohi

  • Between clause in sql query???????

    hello all,
    following sql query is using for a report.
    select trunc(m.spc_doc_date) prod_date,sum(nvl(d.req_qty,0)) order_qty,sum(nvl(d.spc_item_qty,0)) prod_qty
    from spc_ppc_daily_m m, spc_ppc_daily_d d
    where m.spc_doc_# in(select spc_doc_# from spc_ppc_daily_m )
    --and d.blce_qty>0
    and m.spc_locn_code=:locn_code
    and m.spc_doc_date between :TO_date and :FROM_date
    and m.spc_locn_code=d.spc_locn_code
    and m.spc_doc_#=d.spc_doc_#
    and (m.obu=:obu OR :OBU IS NULL)
    and (m.customer=:customer OR :CUSTOMER IS NULL)
    group by trunc(m.spc_doc_date)
    order by trunc(m.spc_doc_date)
    when i use to_date='22-feb-2012' from_date='22-feb-2012'
    no data is fetching.(acually records are there on 22-feb-2012)
    when i use to_date='22-feb-2012' from_date='23-feb-2012'
    now data of 22-feb-2012 is showing.
    i replace the between by >= & <=, result is same both case respectively.
    why?
    Thanks
    yash

    yash_08031983 wrote:
    hello all,
    following sql query is using for a report.
    select trunc(m.spc_doc_date) prod_date,sum(nvl(d.req_qty,0)) order_qty,sum(nvl(d.spc_item_qty,0)) prod_qty
    from spc_ppc_daily_m m, spc_ppc_daily_d d
    where m.spc_doc_# in(select spc_doc_# from spc_ppc_daily_m )
    --and d.blce_qty>0
    and m.spc_locn_code=:locn_code
    and m.spc_doc_date between :TO_date and :FROM_date
    and m.spc_locn_code=d.spc_locn_code
    and m.spc_doc_#=d.spc_doc_#
    and (m.obu=:obu OR :OBU IS NULL)
    and (m.customer=:customer OR :CUSTOMER IS NULL)
    group by trunc(m.spc_doc_date)
    order by trunc(m.spc_doc_date)
    when i use to_date='22-feb-2012' from_date='22-feb-2012'
    no data is fetching.(acually records are there on 22-feb-2012)
    when i use to_date='22-feb-2012' from_date='23-feb-2012'
    now data of 22-feb-2012 is showing.
    Hello yash,
    what is the value of m.spc_doc_date in database ? is it date time ? also what is the format mask of to_date and from_date ?
    Try this
    select trunc(m.spc_doc_date) prod_date,sum(nvl(d.req_qty,0)) order_qty,sum(nvl(d.spc_item_qty,0)) prod_qty
    from spc_ppc_daily_m m, spc_ppc_daily_d d
    where m.spc_doc_# in(select spc_doc_# from spc_ppc_daily_m )
    --and d.blce_qty>0
    and m.spc_locn_code=:locn_code
    and trunc(m.spc_doc_date) between :TO_date and :FROM_date
    and m.spc_locn_code=d.spc_locn_code
    and m.spc_doc_#=d.spc_doc_#
    and (m.obu=:obu OR :OBU IS NULL)
    and (m.customer=:customer OR :CUSTOMER IS NULL)
    group by trunc(m.spc_doc_date)
    order by trunc(m.spc_doc_date)Hopes this helps

  • What value we need to pass as parameter in where clause in select query

    Hi ALL,
    I have written following query, it was executing fine and returning me all the rows with search criteria.
    SELECT *
    FROM
    PRTY_RQST PR
    JOIN BUSN_APPLC BIAP ON BIAP.BUSN_APPLC_ID = PR.BUSN_APPLC_ID
    JOIN INTN_STATS INSTS ON INSTS.INTN_STATS_ID = PR.INTN_STATS_ID
    JOIN INTN_PROCES_TYP INTPTY ON INTPTY.INTN_PROCES_TYP_ID = PR.INTN_PROCES_TYP_ID
    LEFT JOIN RQST_TYP RQSTYP ON RQSTYP.RQST_TYP_ID = PR.RQST_TYP_ID
    JOIN ADDTN_RQST_INFO ADTINF ON PR.PRTY_RQST_ID = ADTINF.PRTY_RQST_ID
    JOIN ADDTN_INFO_KEY_TYP ADDKEY ON ADTINF.ADDTN_INFO_KEY_TYP_ID = ADDKEY.ADDTN_INFO_KEY_TYP_ID
    JOIN PRTY_KEY PRTKEY ON PR.PRTY_RQST_ID = PRTKEY.PRTY_RQST_ID
    JOIN PRTY_KEY_TYP PRKYTP ON PRTKEY.PRTY_KEY_TYP_ID = PRKYTP.PRTY_KEY_TYP_ID
    WHERE (BIAP.BUSN_APPLC_NM = 'bpel')
    AND (INTPTY.INTN_PROCES_TYP_NM = 'FulfillmentOrder')
    AND (PR.UPDT_BY = 'update3')
    AND (INSTS.INTN_STATS_NM = 'Submitted')
    AND (PR.CHLD_RQST_IND = 'N')
    AND (PR.TRACK_RQST_IND = 'Y')
    AND (RQSTYP.RQST_TYP_NM = 'PensionPortfolioRebalance')
    AND (RQSTYP.RQST_CLASS_NM = 'Composite')
    AND (PRKYTP.PRTY_KEY_TYP_NM = 'NPIN')
    AND (PRTKEY.PRTY_TYP_VAL = '101101' )
    AND (ADDKEY.ADDTN_INFO_KEY_TYP_NM = 'PlanNumber')
    AND (ADTINF.ADDTN_RQST_TYP_VALUE = 'TBMBUpdated');
    My question here is i don't want pass the value for BIAP.BUSN_APPLC_NM, still want to get the values for remaing conditions. what value i need to pass here.
    I tried Null it giving me no rows. can some one help me on this.
    Thank you in advance.
    Vijay

    933325 wrote:
    thank you,
    since it is search criteria. I have to use OR instead of AND. this resolved my problem.
    SELECT *
    FROM
    PRTY_RQST PR
    JOIN BUSN_APPLC BIAP ON BIAP.BUSN_APPLC_ID = PR.BUSN_APPLC_ID
    JOIN INTN_STATS INSTS ON INSTS.INTN_STATS_ID = PR.INTN_STATS_ID
    JOIN INTN_PROCES_TYP INTPTY ON INTPTY.INTN_PROCES_TYP_ID = PR.INTN_PROCES_TYP_ID
    LEFT JOIN RQST_TYP RQSTYP ON RQSTYP.RQST_TYP_ID = PR.RQST_TYP_ID
    JOIN ADDTN_RQST_INFO ADTINF ON PR.PRTY_RQST_ID = ADTINF.PRTY_RQST_ID
    JOIN ADDTN_INFO_KEY_TYP ADDKEY ON ADTINF.ADDTN_INFO_KEY_TYP_ID = ADDKEY.ADDTN_INFO_KEY_TYP_ID
    JOIN PRTY_KEY PRTKEY ON PR.PRTY_RQST_ID = PRTKEY.PRTY_RQST_ID
    JOIN PRTY_KEY_TYP PRKYTP ON PRTKEY.PRTY_KEY_TYP_ID = PRKYTP.PRTY_KEY_TYP_ID
    WHERE (BIAP.BUSN_APPLC_NM = null )
    OR (INTPTY.INTN_PROCES_TYP_NM = 'FulfillmentOrder')
    OR (PR.UPDT_BY = 'update3')
    OR (INSTS.INTN_STATS_NM = 'Submitted')
    OR (PR.CHLD_RQST_IND = 'N')
    OR (PR.TRACK_RQST_IND = 'Y')
    OR (RQSTYP.RQST_TYP_NM = 'PensionPortfolioRebalance')
    OR (RQSTYP.RQST_CLASS_NM = 'Composite')
    OR (PRKYTP.PRTY_KEY_TYP_NM = 'NPIN')
    OR (PRTKEY.PRTY_TYP_VAL = '101101' )
    OR (ADDKEY.ADDTN_INFO_KEY_TYP_NM = 'PlanNumber')
    OR (ADTINF.ADDTN_RQST_TYP_VALUE = 'TBMBUpdated');
    AND (ADTINF.ADDTN_RQST_TYP_VAL_DT ='06-JUN-12 04.18.56.000000000 PM')
    AND (ADTINF.ADDTN_RQST_TYP_VAL_NUM ='123123') ;
    once again thank you all.But that's a completely different query than what was in the original post

  • Where clause in select query

    Hi Experts,
    I want to fetch data from PAYR table where ZALDT date falls in the date range(s_date) or VOIDD date falls in the date range.
    Which one is correct?
    SELECT ZBUKR
                 CHECT 
                ZALDT
                VOIDD
    into table T_PAYR
    from PAYR
    where CHECT in s_chect
        and ZALDT in s_date
          or VOIDD in s_date.
          OR
    SELECT ZBUKR
                 CHECT 
                ZALDT
                VOIDD
    into table T_PAYR
    from PAYR
    where CHECT in s_chect
        and ( ZALDT in s_date or VOIDD in s_date ).
    Regards,
    Sangeeta.

    hi,
    Second one is correct
    Issue resolved,please close the thread.
    Thnks
    Sahil

  • Select query taking more time..

    Hi friends..
    The below inner join statement is taking more time ,  can any  body sugget me to improve the performance . I tried FOR ALL ENTRIES also but that also taking more time than inner join statement .
    SELECT a~vbeln from vbap as a inner join vakpa as b
          on avbeln = bvbeln
          into corresponding fields of table IT_VAKPA
          where a~WERKS IN S_IWERKS
          and a~pstyv NE 'ZRS'
          and b~vkorg = IVKORG
          and b~audat IN IAUDAT
          and b~vtweg IN IVTWEG.
    Regards
    Chetan

    Hi Chetan ,
    VAKPA is an index table. From the select query , it has been observed that you are not fetching any data from VAKPA. Only you have added some selection paramenters in where clause of select query.
    My suggestion will be instead of using VAKPA in inner join you use VBAK along with VBAP. All the fields that you are using as selection condition from VAKPA are there in VBAK.
    I am sure performance of query will be improved.
    If still duo to business logic you need to use VAKPA, try to create secondary non unique index on fields VKORD,AUDATand VTWEG on table VAKPA.
    However I will recommend you to go for first option only. If this does not work then go for second option.
    Hopfully this will help you.
    Regards,
    Nikhil

  • Questions on the most efficient select query..

    What is the difference between the two select query & please explain y is the 2nd select query more efficient??
    DATA: MAX_MSGNR type t100-msgnr.
    MAX_MSGNR = '000'.
    SELECT * FROM T100 INTO T100_WA
      WHERE SPRSL = 'D' AND
            ARBGB = '00'.
      CHECK: T100_WA-MSGNR > MAX_MSGNR.
      MAX_MSGNR = T100_WA-MSGNR.
    ENDSELECT.
    DATA: MAX_MSGNR type t100-msgnr.
    SELECT MAX( MSGNR ) FROM T100 INTO max_msgnr
      WHERE SPRSL = 'D' AND
            ARBGB = '00'.

    Hi,
    First never use Check statement in the Select.
    Next thing Select ... end select.
    Coming to ur question In case of first select it will fetch each record from the data base and compares that record value with the variable(MAX_MSGNR) and assigns the value to the variable. And this process will continue till the select reads all the records of the data base. Also these operations happens on the data base server. SO this query not only affect ur program but also others who is accessing the same data base.
    Second query is most efficient because of the aggregate function MAX. Here it will fetch all the records in single go and checks the max value for that column using
    optimising algorithm. So number of checks, assignments(single assignment) and fetches will be less compared to first select. This is the main reason. Hope this clarified ur doubt.
    Another thing is in first query we are selecting all the fields where as in second we are selecting only one field(required)
    Thanks,
    Vinod.
    Edited by: Vinod Kumar Vemuru on Mar 13, 2008 4:55 PM

  • Simple Select query with 'where', 'and', 'between' clauses takes time

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

  • Perf tuning issue with a query involving between clause

    Hi all,
    I am getting issues with performance when I try to execute this query. Given below the query and it is going for a full table scan. I think the problem is with the between clause. But I dont know how to resolve this issue
    SELECT psm.member_id
    FROM pre_stg_member psm
    WHERE psm.map_tran_agn BETWEEN :start_transaction_agn and :end_transaction_agn
    and psm.partition_key = :p_partition_key;
    Having composite index on map_tran_agn and partition_key.
    Please help me in this regard.
    Thanks,
    Swami

    Please consider the following when you post a question.
    1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
    You can use the following query and do a copy past of the output.
    select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
    that are asked the answer is already there.
    3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
    I have the following table called sales
    with sales
    as
          select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
          union all
          select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
    select *
      from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
    For example in the above sales table, I want to know the total quantity and number of invoice for each product.
    The output should look like this
    Prod_id   sum_qty   count_inv
    1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
    6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
    Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
    use the {noformat}{noformat} tags.
    The usage of the tag is like this.
    <place your code here>\
    7. If you are posting a *Performance Related Question*. Please read
       {thread:id=501834} and {thread:id=863295}.
       Following those guide will be very helpful.
    8. Please keep in mind that this is a public forum. Here No question is URGENT.
       So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Query With BETWEEN Clause Slows Down

    hi,
    I am experiencing slow down query by using BETWEEN clause. Is there any solution for it?

    Here is the difference if I use equal not between.
    SQL> select to_char(sysdate,'MM-DD-YYYY HH24:MI:SS') from dual;
    TO_CHAR(SYSDATE,'MM
    11-14-2005 15:44:03
    SQL> SELECT COUNT(*) /*+ USE_NL(al2), USE_NL(al3), USE_NL(al4),
    2 USE_NL(al5), USE_NL(al6) */
    3 FROM acct.TRANSACTION al1,
    4 acct.account_balance_history al2,
    5 acct.ACCOUNT al3,
    6 acct.journal al4,
    7 acct.TIME al5,
    8 acct.object_code al6
    9 WHERE ( al1.reference_num = al4.reference_num(+)
    10 AND al1.timekey = al5.timekey
    11 AND al5.timekey = al2.timekey
    12 AND al3.surrogate_acct_key = al2.surrogate_acct_key
    13 AND al3.surrogate_acct_key = al1.surrogate_acct_key
    14 AND al1.report_fy = al3.rpt_fy
    15 AND al6.object_code = al1.object_adj
    16 )
    17 AND ((al1.timekey = 20040701
    18 or al1.timekey = 20040801
    19 or al1.timekey = 20040901
    20 or al1.timekey = 20041001
    21 or al1.timekey = 20041101
    22 or al1.timekey = 20041201
    23 or al1.timekey = 20050101
    24 or al1.timekey = 20050201
    25 or al1.timekey = 20050301
    26 or al1.timekey = 20050401
    27 or al1.timekey = 20050501
    28 or al1.timekey = 20050601
    29 or al1.timekey = 20050701
    30 or al1.timekey = 20050801
    31 or al1.timekey = 20050901)
    32 AND al3.dept = '480');
    COUNT(*)/*+USE_NL(AL2),USE_NL(AL3),USE_NL(AL4),USE_NL(AL5),USE_NL(AL6)*/
    34245
    SQL> select to_char(sysdate,'MM-DD-YYYY HH24:MI:SS') from dual;
    TO_CHAR(SYSDATE,'MM
    11-14-2005 15:44:24

Maybe you are looking for