Need a select statement

Hi,
I have a table:
table: Acct_Hist
(Acct_id number,
Acct_type_id number,
Acct_ver_id number,
Acct_bal number,
Acct_low_bal number)
I want to retrieve all accounts where there is a change in acct_type_id.
Please help me.

It is always helpful when you post here to provide the following:
1. Oracle version (e.g. 10.2.0.4)
2. Sample data in the form of CREATE and INSERT statements. You have provided us the CREATE statement but no data to work with.
3. Expected results.
4. Logic to achieve the expected results.
5. Please use \ tags for #2 and #3.
Edited by: Centinul on Nov 30, 2009 1:16 PM
Removed SQL until further clarification is provided.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Need a select statement to trim a single value out of a column

    I have a column which can and does contain single and multiple values. For instance, there could be a single value, value, or it could look like this value, value, with there being a comma and a space between the two values. I need a select statement that will only and always return the value to the left or in the case of a single value with no comma, just that value. TIA

    If your single value has no comma, just the value, then you need an extra DECODE to resolve that case.
    SELECT DECODE(INSTR(text,','),0,text,SUBSTR(text,1,INSTR(text,',')-1))
    FROM (SELECT 'value1' text
          FROM dual       
          UNION       
          SELECT 'value2, value3'
          TEXT from dual)TTFN
    John

  • Help need in select statement?

    Hi experts...
    I have an internal table with 2 records...i_mara with fields matnr and ersda
    matnr   ersda
    2345    01/26/2007
    3445    02/05/2007
    i need to write a select statement to collect all MBLNR from MKPF table where BUDAT is in between 01/26/2007 and 02/05/2007..
    Thanx
    Giri

    HI vasanth and rich...
    thanks for replies...
    vasanth i am getting error with the statement.. so i assigned 6 points to u..
    DATA: RA_BUDAT RANGE OF BUDAT WITH HEADER LINE.
    Unable to interpret range.... Possible error with spelling or comma
    Rich: ur solution worked good....
    is there any possible simplest way... or this is the best way includes performance?
    Regards
    Giri

  • Help needed in select statement

    Hi gurus,
    I have a table with orderentry and ordertype
    case 1 :
    i want to get the set of records when ordertype =1 repeats
    case2:
    i want to get the set of records when there is no ordertype =1
    CREATE TABLE test
    orderentry NUMBER,
    ordertype NUMBER
    INSERT into test
    values ( 10,1);
    INSERT INTO test
    VALUES (10, 2);
    INSERT INTO test
    VALUES (10, 1);
    INSERT INTO test
    VALUES (10, 2);
    INSERT INTO test
    VALUES (11, 1);
    INSERT INTO test
    VALUES (11, 2);
    INSERT INTO test
    VALUES (11, 2);
    INSERT INTO test
    VALUES (11, 2);
    INSERT INTO test
    VALUES (12, 1);
    INSERT INTO test
    VALUES (12, 1);
    INSERT INTO test
    VALUES (12, 2);
    INSERT INTO test
    VALUES (12, 2);
    INSERT INTO test
    VALUES (13, 2);
    INSERT INTO test
    VALUES (13, 2);
    INSERT INTO test
    VALUES (13, 2);
    COMMIT;
    I want the set of records when the ordertype 1 repeats
    my result should be:
    case 1:
    orderentry ordertype
    10 1
    10 2
    10 1
    10 2
    12 1
    12 1
    12 2
    12 2
    case 2:
    orderentry ordertype
    13 2
    13 2
    13 2
    Thanks in advance

    Hello
    Thank yuo for posting the create table statements and sample data. I think these do what you are looking for
    --case 1
    SELECT
        orderentry,
        ordertype
    FROM
            SELECT
                orderentry,
                ordertype,
                COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
            FROM
                t_test
    WHERE
        ct > 1
    --case 2
    SELECT
        orderentry,
        ordertype
    FROM
            SELECT
                orderentry,
                ordertype,
                COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
            FROM
                t_test
    WHERE
        ct = 0
    DTYLER_APP@pssdev2> select * from t_test;
    ORDERENTRY  ORDERTYPE
            10          1
            10          2
            10          1
            10          2
            11          1
            11          2
            11          2
            11          2
            12          1
            12          1
            12          2
            12          2
            13          2
            13          2
            13          2
    15 rows selected.
    DTYLER_APP@pssdev2> SELECT
      2      orderentry,
      3      ordertype
      4  FROM
      5      (
      6          SELECT
      7              orderentry,
      8              ordertype,
      9              COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
    10          FROM
    11              t_test
    12      )
    13  WHERE
    14      ct > 1
    15  /
    ORDERENTRY  ORDERTYPE
            10          1
            10          2
            10          1
            10          2
            12          1
            12          1
            12          2
            12          2
    8 rows selected.
    DTYLER_APP@pssdev2> SELECT
      2      orderentry,
      3      ordertype
      4  FROM
      5      (
      6          SELECT
      7              orderentry,
      8              ordertype,
      9              COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
    10          FROM
    11              t_test
    12      )
    13  WHERE
    14      ct = 0
    15  /
    ORDERENTRY  ORDERTYPE
            13          2
            13          2
            13          2
    3 rows selected.

  • How do I return the results of two SELECT statements in to one result?

    I want to do this without using UNION.
    Here's an example of what I'm trying to do:
    I have a table called COUNTRY with the following columns:
    COUNTRY
    COUNTRY_CODE
    DATE_VISITED_LAST
    POPULATIONI have another table called STATE_COUNTY with the following columns:
    STATE_COUNTY
    COUNTRY_CODE
    STATE_COUNTY_CODE
    DATE_LAST_VISITED
    POPULATIONI have a third table called TOWN with the following columns:
    TOWN
    COUNTRY_CODE
    STATE_COUNTY_CODE
    TOWN_CODE
    DATE_LAST_VISITED
    POPULATIONNow through the interface I have, a user will supply a country code. I need a SELECT statement that will return a table with the following result set:
    The COUNTRY_CODE entered including the DATE_LAST_VISITED and POPULATION for this country
    ------> All the associated STATE_COUNTY's belonging to this country along with the DATE_LAST_VISITED and POPULATION for each STATE_COUNTY_CODE.
    -------------> All the associated TOWN_CODE's belonging to this state_county and country along with the DATE_LAST_VISITED and population for each TOWN.
    So the table will have 9 columns:
    COUNTRY
    DATE_LAST_VISITED_COUNTRY
    POPULATION_COUNTRY
    STATE_COUNTY
    DATE_LAST_VISITED_STATE_COUNTY
    POPULATION_COUNTY
    TOWN
    DATE_LAST_VISITED_TOWN
    POPULATION_TOWNAny ideas how this can be done?
    Thanks.

    Hi guys,
    Would it be ok to do it like this (with a join):
    SELECT      
         c.country_code,
         c.date_last_visited AS DATE_LAST_VISITED_COUNTRY,
         c.population AS POPULATION_COUNTRY,
         s.state_county_code,
         s.date_last_visited AS DATE_LAST_VISITED_STATE_COUNTY,
         s.population AS POPULATION_COUNTY,
         t.town_code,
         t.date_last_visited AS DATE_LAST_VISITED_TOWN,
         t.population POPULATION_TOWN,
    FROM
         country c
         LEFT OUTER JOIN state_county s ON s.country_code = c.country_code
         LEFT OUTER JOIN town       t ON t.country_code = s.country_code
    AND                                       t.state_county_code = s.state_county_codeThe results required would be something like:
    Country_Code     DATE_LAST_VISITED_COUNTRY     POPULATION_COUNTRY     STATE_COUNTY_CODE         DATE_LAST_VISITED_STATE_COUNTY         POPULATION_COUNTY     TOWN_CODE     DATE_LAST_VISITED_TOWN     POPULATION_TOWN
    UK               14-JAN-09                     56,00000               London                    18-JUL-99                              23,0000               Ascot         30-JUN-89                  12,000
                                                                                                                                                                 Brixton       28-JAN-92                  4,684
                                                                          Birmingham                12-SEP-09                              55,678                Solihull      12-OCT-81                  6.768 Does this make sense?
    Thanks!
    Edited by: Sastry on Nov 2, 2009 2:04 AM

  • Function in select statement need to be called only for the last record.

    Select state,
    local,
    fun_state_loc_other_details(19) details
    from state_local
    where pm_key=19
    resuts:_
    State Local Details
    AP APlocal details1
    UP UPLocal details1
    MP MPLocal details1
    i) The above query returns 100 records
    ii) fun_state_loc_other_details is also getting called 100 times. But I want this function to be called only for the last record that is 100th record.
    is there any way to do that?

    Thanks amatu.
    One more small query. Can I do it on condition based.
    Select state,
    local,
    fun_state_loc_other_details(19) details
    from state_local
    where pm_key=19
    Like if one state it need to be called once.
    AP -- 50 records
    UP - 20 records
    MP -- 10 records.
    fyi: this record no. varies
    I want the function to be called for AP once, UP once, MP once.

  • Need help in how to combine select statement

    Hi,
    Table1 (VIEWREST2005)
    - ip
    - msg
    - fulldata
    - ID
    Table2 (L200505)
    - ip
    - msg
    - fulldata
    I want to create one sql that can select from table 2 to table number 1. This is my select statement, but it cannot running. The different between this 2 table is only column ID.
    insert into VIEWREST2005(ip,msg,fulldata) values(select ip, msg,fulldata from L200505)
    Can anyone modified my sql statement.

    Why do you not refer to the Oracle® Database SQL Reference manual? Or do you think your SQL Kung Fu is good enough that no RTFM'ing is needed?
    On-line copies of all Oracle documentation is available via http://tahiti.oracle.com/
    BTW, the correct syntax for this flavoured INSERT is:
    INSERT INTO table SELECT .. FROM table
    Drop the VALUES clause as no literal values are supplied.

  • Need to create a transaction for multiple select statements?

    Hello,
    I am a newbie and have a question about database transaction, e.g. whether/not to enclose multiple select statements (and select statements only) into a transaction.
    My database is set to transaction isolation level 2: REPEATABLE READ, where dirty read & non-repeatable read are not allowed, only phantom read is allowed.
    Now, in my code I have a number of methods that only contain select statements only. Since they are merely select statements, which don't do any modifications to the data, I am not sure if I am supposed to enclose them into a transaction.
    However, if I don't put them into a transaction will the transaction isolation level takes into effect automatically when another user is modifying the data that I am reading? In other words, I need to make sure the select statements will never do either dirty read or non-repeatable read. But I am not sure if it is necessary to enclose multiple select statements in a transaction, since I believe putting the select statements into a transaction will put some locks to the data being read which may reduce the concurrency of my application.
    Any help/advice would be very much appreciated.
    Duane

    You might want to try asking this on a forum that specific to your database. I suspect the answer can vary depending on the database and probably requires in depth knowledge of what the database does.

  • Need help on select statement...

    Hi,
    I need to fetch from vbfa table those records where vbeln starts with '0800'.
    my select statement given below gives a syntax error..pl help.
    SELECT * FROM vbfa WHERE vbeln(4) = '0800'.
    vbeln(4) is not accepted and i get the message ' field vbeln(4) is unknown' ...what to do?
    thks

    Use LIKE. Please see F1 on this.
    Rob
    (changed CP to LIKE)
    Edited by: Rob Burbank on Sep 15, 2008 11:18 AM

  • Need to wite pl sql procedure for dynamic select statement

    Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
    select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;

    I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
    TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM'))

  • Need help with select statement or query

    Not familiar with what to call it, but here is what i need...
    To give our analyst a better idea of warranty on some of our
    equipment, i
    would like to add to the page a column that displays if the
    device is still
    under warranty
    I currently capture the date the equipment was returned from
    repair, so what
    could i use within my select statement or query to display a
    warranty
    expiration date or display on the page...
    example :
    Returned from repair 10/20/2006 warranty expires on
    11/20/2006
    each equipment has different warranties, so i need a formula
    or something to
    say... device #1 has 60 day warranty ( so 10/20/2006 + 60days
    =
    12/19/2006 )
    I would imagine this to be a query
    Table 1 would contain the equipment type and warranty time
    Table 2 would contain the current status of the equipment
    Query would take the back from repair date + warranty =
    expiration date

    Simple. Join the two tables and create a derived column for
    the expiration date. The exact syntax is dependant on your DBMS, so
    check the manual for whichever you are using and look at the date
    functions. There will be a function that will allow you to add a
    number of date units (day, month, year, etc) to a date
    field.

  • Select statement info needed

    Hello all,
    My req. with select statement is as below.
    Need to select all materials from MARA where the product hierarchy (PRDHA) contains u20180050000501u2019 as the first ten characters,  and insert them into an internal table .
    awaiting for earlier response.
    Thanking you.
    Bharat.

    Hi,
    Check this code..
    data: t_mara type standard table of mara.
    * Make sure to remove * and check whether there is an index on the field PRDHA.
    SELECT * FROM MARA INTO TABLE t_mara
                 where PRDHA LIKE '0050000501%'.
    Thanks
    Naren

  • Need suggestions on my select statement.

    Hello experts,
    I am having with my select statement since it is running very slow. Normally, the itab it_vendor has records exceeding 7,000. So it loops 7, 000 times and I have 2 select statements which adds to the performance slowdown. Here it is guys:
    *Select records records from BSIK and BSAK based on itab it_vendor
        LOOP AT it_vendor.
    *Select records from BSIK
          SELECT belnr lifnr budat buzei gjahr sgtxt dmbtr
                shkzg saknr hkont zlspr FROM bsik
           INTO TABLE it_bsak
           FOR ALL ENTRIES IN it_vendor
           WHERE bukrs EQ p_bukrs
             AND budat LE p_keydt
             AND hkont IN so_saknr
             AND lifnr EQ it_vendor-lifnr
             AND umsks EQ space
             AND umskz EQ space.
    *Select records from BSAK
          SELECT belnr lifnr budat buzei gjahr sgtxt dmbtr
                 shkzg saknr hkont zlspr FROM bsak
            APPENDING TABLE it_bsak
            FOR ALL ENTRIES IN it_vendor
            WHERE bukrs EQ p_bukrs
              AND augdt GT p_keydt
              AND budat LE p_keydt
              AND hkont IN so_saknr
              AND lifnr EQ it_vendor-lifnr
              AND umsks EQ space
              AND umskz EQ space.
        ENDLOOP.

    Since you are using the FOR ALL ENTRIES extension of the select statement, you should not have these inside the loop.  What it is correctly doing is getting all the records for all the vendors every time thru the loop.  The FOR ALL ENTRIES will get all the records for all of the vendors in one shot, no need to LOOP at the internal table.  Make sure that you change your where clauses to how I have them below.
    * Get the IT_VENDOR itab here
    <b> check not it_vendor[] is initial.
    sort it_vendor ascending by lifnr .</b>
    *Select records from BSIK
    SELECT belnr lifnr budat buzei gjahr sgtxt dmbtr
    shkzg saknr hkont zlspr FROM bsik
    INTO TABLE it_bsak
    FOR ALL ENTRIES IN it_vendor
    WHERE<b> lifnr EQ it_vendor-lifnr</b>
    and  bukrs EQ p_bukrs
    AND budat LE p_keydt
    AND hkont IN so_saknr
    AND umsks EQ space
    AND umskz EQ space.
    *Select records from BSAK
    SELECT belnr lifnr budat buzei gjahr sgtxt dmbtr
    shkzg saknr hkont zlspr FROM bsak
    APPENDING TABLE it_bsak
    FOR ALL ENTRIES IN it_vendor
    WHERE  <b>lifnr EQ it_vendor-lifnr</b>
    and bukrs EQ p_bukrs
    AND augdt GT p_keydt
    AND budat LE p_keydt
    AND hkont IN so_saknr
    AND umsks EQ space
    AND umskz EQ space.
    Regards,
    Rich Heilman

  • Need Select statement for fetch the details

    Hi
      i want to fetch particular customer wise sales orderds and that sales order No  and  date of sales order was created..  and  that sales order related PO No  and Materials ..
    for this..   how can i write an executable programm.. is it needed to  define seperate  internal tables or single internal table is enough  ?
    what is the select statement for fetching  all these details..
    any help will be appriciated
    Thanks
    Bbau

    custmer master table is KNA1  knb1  knbk
    sales data tables r  VBAK VBAP VBEP
    Material data  MARA, MARAC, MARD
    PO RELATED ekko  ekpo  eket
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Feb 13, 2008 3:04 PM

  • Need help in logic change to avoid select statement inside loop .

    Hello all ,
    Please see the below code . Here i got the shipment number in internal table  IT_VTTK . So For this shipment number i want to get the details from Vekp table in to internal table  IT_VEKP  . There is no need for me to use For all entries . I have passed the value of it_vekp into work area wa_vekp and getting the details in to IT_vekp using loop.
    But since we should not use the select statement inside the loop , Can anybody please tell me how to achieve this functionality .
    Instead of passing into work area wa_vttk if i directly use the internal table I'm getting the following error .
    "IT_VTTK" is a table without a header line and therefore has no component called "TKNUM".
    Hence i have used select statement inside a loop . Please tell me is there any other way to avoid this ?
    types:begin of ty_likp,
            vbeln type likp-vbeln,
           end of ty_likp,
           begin of ty_vttk,
            tknum type vttk-tknum,
            end of ty_vttk.
    DATA: IT_VEKP TYPE STANDARD TABLE OF TY_VEKP,
          WA_VEKP TYPE TY_VEKP.
      data:it_likp type standard table of ty_likp,
           wa_likp type ty_likp,
           it_likp1 type standard table of ty_likp,
           it_vttk type standard table of ty_vttk,
           wa_vttk type ty_vttk.
      data:w_tknum type vttk-tknum.
    if not it_likp is initial .
        select vbeln
                from
                 vbfa
          into table it_vttk
           for all entries in it_likp where vbelv = it_likp-vbeln and vbtyp_n = '8'.
      endif .
    IF IT_VTTK[] IS NOT INiTIAL.
        loop at it_vttk into wa_vttk.
        SELECT venum
               EXIDV
               EXIDV2
               BRGEW
               NTGEW
               GEWEI
               TARAG
               GEWEI
               VHART
               INHALT
             FROM VEKP INTO TABLE IT_VEKP where VPOBJKEY = wa_vttk-tknum  and vpobj = '4'.
          endloop.
          endif.

    Hello,
    Why would you not like to use FOR ALL ENTRIES in the second select? Is it becasue of the length or type mismatch error between the fields VPOBJKEY and wa_vttk-tknum ?
    Vikranth

Maybe you are looking for

  • About  creating data source(urgent)

    Hi, I am abap developer. i don't know much about crm. our requirement is : i need to create one infoset in sap r/3. we want to use that infoset in crm server  to create data source. we use transaction code : CRMD_MKTDS We specify these values. Origin

  • How to resize all pages -Acrobat 9 Pro Extended ? ?

    I came across a pre-existing pdf file of an old book of genealogy.  According to the front pages, it was 'Digitized by Microsoft', so I know nothing on how it was generated.  Total pages are in excess of 1,100. In viewing the pages, they are reflecte

  • Re-peating the output in sales order

    Hi, When we create a sales order and save it , the output is issued through output type. We are now facing an issue. when we do some changes in the sales order (manually or batch job), the output is not re-triggred. how to re-trigger the output. It c

  • Material non cenvatable

    Dear All, I am having a scenario, PO- 100 inr Excise- 10 inr Vat- 5.5, I don't know while making PO where i will avail cenvat or not. Now at the time of GR i know that i am not availing the cenvat credit. So i manually make the material non cenvatabl

  • Will leaving the charger in hurt the battery on the New MBP 17"

    I rarely need to unplug my new MBP 17", but with all the talk about battery problems, I wonder if I should unplug it from time to time and not just leave it plugged in. Right now its been plugged in for a 1.5 weeks... While I don't think this could h