Help with selecting chuncks of data from a table

Hi all,
I need help with a query that should do the following.
I have a table with vessel messages, and I need to get the last "NumMsgs" messages from a group of vessels.
The problem I have is that if I order the table by Vessel_ID, MessageDate DESC, I can´t do ROWNUM < NumMsgs (<-- Then number of messages to be shown is a user parameter)
I know it should be something like:
select * from (
select *
from Messages m
where TRIM(m.V_ID) = '11597' /* I was trying for a single vessel atm */
order by m.V_ID, m.MESSAGEDATE desc
where rownum < :NumMsgs
Any ideas?
Thanks in advance !

Hi,
What about :
select *
from (
select m.*, row_number() (order by m.V_ID, m.MESSAGEDATE desc) rn
from Messages m
where TRIM(m.V_ID) = '11597' /* I was trying for a single vessel atm */
where rn < :NumMsgsAnyway, I don't very well understand your problem, your query work fine, see for example :
SQL> ed
Wrote file afiedt.buf
  1  select object_name, object_id
  2  from
  3  (select object_name, object_id, row_number() over (order by object_id desc) as rn
  4   from dba_objects)
  5* where rn < 4
SQL> /
PS_TL_MTCHD_118     71763
PS_TL_MTCHD_117     71762
PS_TL_MTCHD_116     71761
SQL> ed
Wrote file afiedt.buf
  1  select object_name, object_id
  2  from
  3  (select object_name, object_id
  4   from dba_objects
  5   order by object_id desc)
  6* where rownum < 4
SQL> /
PS_TL_MTCHD_118     71763
PS_TL_MTCHD_117     71762
PS_TL_MTCHD_116     71761
SQL> Nicolas.
Message was edited by:
N. Gasparotto

Similar Messages

  • Help with writing and retrieving data from a table field with type "LCHR"

    Hi Experts,
    I need help with writing and reading data from a database table field which has a type of "LCHR". I have given an example of the original code but don't know what to change it to in order to fix it and still read in the original data that's stored in the LCHR field.
    Basically we have two Function modules, one that saves list data to a database table and one that reads in this data. Both Function modules have an identicle table which has an array of fields from type INT4, CHAR, and type P. The INT4 field is the first one.
    Incidentally this worked in the 4.7 non-unicode system but is now dumping in the new ECC6 Unicode system.
    Thanks in advance,
    C
    SAVING THE LIST DATA TO DB
    DATA: L_WA(800).
    LOOP AT T_TAB into L_WA.
    ZDBTAB-DATALEN = STRLEN( L_WA ).
    MOVE: L_WA to ZDBTAB-RAWDATA.
    ZDBTAB-LINENUM = SY-TABIX.
    INSERT ZDBTAB.
    READING THE DATA FROM DB
    DATA: BEGIN OF T_DATA,
                 SEQNR type ZDBTAB-LINENUM,
                 DATA type ZDBTAB-RAWDATA,
               END OF T_TAB.
    Select the data.
    SELECT linenum rawdata from ZDBTAB into table T_DATA
         WHERE repid = w_repname
         AND rundate = w_rundate
         ORDER BY linenum.
    Populate calling Internal Table.
    LOOP AT T-DATA.
    APPEND T_DATA to T_TAB.
    ENDLOOP.

    Hi Anuj,
    The unicode flag is active.
    When I run our report and then to try and save the list data a dump is happening at the following point
    LOOP AT T_TAB into L_WA.
    As I say, T_TAB consists of different fields and field types whereas L_WA is CHAR 800. The dump mentions UC_OBJECTS_NOT_CONVERTIBLE
    When I try to load a saved list the dump is happening at the following point
    APPEND T_DATA-RAWDATA to T_TAB.
    T_DATA-RAWDATA is type LCHR and T_TAB consists of different fields and field types.
    In both examples the dumps mention UC_OBJECTS_NOT_CONVERTIBLE
    Regards
    C

  • Help with accessing same keychain data from two apps with bundled appid

    I have two ios apps that I'd like to share the same keychain data.  
    According to the apple docs, this should be possible as long as I've set up the appid with a wild card, which I did from the provisioning portal:
    appid:   bundleID.*
    Then, in the AIR for IOS settings of the flash ide, in the App ID field, I made the two apps be members fo the this appid:  bundleID.app1 and bundleID.app2
    But when I use the EncriptedLocalStore class to access the data from one of the apps that the other app stored, it isn't available.
    But each app, independently, is successfully writing to/reading data from the keychain.
    From what I've read, I'm doing everything right.  But clearly I'm not because it isn't working.

    hi dear
    the link which you have send is really too helpful
    but when i am using the way shown there and as  directed it shows an error that
                 'DataSource - Table not found'
    i think this is because the temprary table we r using is neither user defined nor SBO table.
    so plz tell me some way.

  • Help with selecting 10 random records from all records meeting report selection criteria in Crystal 11

    <p>I am trying to select ten random records from all that match the report selection criteria then report on each of these random records for QA/QI.  I have tried the RND function however it is giving me a random number rather than a random record selection.  I cannot figure this out and am despirately seeking assistance.</p><p>Thank you,</p><p>Amy</p>

    <p>I don&#39;t know of any Random record selection functions but maybe you could write your own custom function inside of a record selection to randomly filter the records.  You would use the Rand function we currently have to decide if a record was included in the report data or not.</p><p>Another possible option is to filter the records before they get to the report.  You can only do this if you are pushing the data into the report instead of having the report pull the data.  An example of this would be passing an ado recordset to a report at runtime. </p><p>Rob Horne</p><p>http://diamond.businessobjects.com/blog/10 </p>

  • Help in ABAP rountine : reading data from masterdata table

    Hi,
    I would like to have a rountine in my transformation rule (BI 7)
    scenario
    I have an info object (PROD) that has attributes such as Price which is key figure and prod group char.
    I have  KeyFigures  info object REV and QUANTITY and would like to have a rountine that perform the following calculation
    REV = Price * QUantity.
    I tried using formula when loading transactional data  but I could only find Quantity but not price which made it difficult for me.
    Now
    I would like to have a routine in REV transformation that reads the Price data from infoobject PROD master data table and multiply it with Quantity.
    thanks

    hi,
    since price is an attribute u cannot use it in calculation straight a way.
    if u need to use in formula, make the price as ordinary key figure and do it.
    these type of calculation can be done at report level.
    Key figure as attribute
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/72f4a790-0201-0010-5b89-a42a32223ffc
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/009819ab-c96e-2910-bbb2-c85f7bdec04a
    Ramesh

  • [b]export data from a table to a csv or .txt file[/b]

    hi plz i need help in how to export data from a table to a csv or .txt file

    If you are using TOAD, then you can execute the statement like SELECT * FROM TABLE1
    Then, you can go to Output Grid and you can say save as and you can save it as you want, excel, tab delimited or whatever.
    Thanx,
    Cheers,

  • Displaying data from multiple table/column

    hello ..
    anybody can help me how to diplaying data from multiple table/ column in PHP. TQ

    Follow the "How do I SELECT, INSERT, UPDATE and DELETE data from PHP?" example from http://wiki.oracle.com/page/PHP+Oracle+FAQ and change the "select ..." query to your favourite join, e.g.
    select country_name, region_name from countries, regions where countries.region_id = regions.region_id;

  • ALV OOps report- getting data from two tables and adding issue

    Hi,
    This is sales employee performance report.
    I need to select all the fields from two tables based on user input ie VKorg, sales employee .
    There is one field callled " Net sales"in both the tables.
    Based on sales employee number, i need to add that net sales which i get from two tables.
    I need to generate single report.
    Can you give some inputs reg. the select query.
    My idea is select all the data from both tables using join statement.
    Thanks

    Hi,
    I have written like this:
    select * from S002 as a join S006 as b
        into table ME->SS002_RAW[]
        where vkorg in me->select_parameters->SO_VKORG[] = vkorg in me->select_parameters->SO_VKORG[]
              and ZZSLSEMP01 in me->select_parameters->SO_so_empl[] = ZZSLSEMP02 in me->select_parameters->SO_so_empl[].
    when i do like that,
    I am getting error
    Incorrect structure of FROM clause . . . .     
    If you give some idea on this
    Edited by: Raja on Apr 22, 2009 11:19 AM

  • MySQL move date from one table to another

    I was wondering if there is a MySQL command that will let me move a selected row of data from one table to another. both tables have the same columns and declaration type (one table is actually an archived table on old data)
    example
    I wasnt to move all data in Table1 where the date is greater than 30 days old to Table 2
    -- so the result should be...import all rows to Table 2 where the date is greater than 30 days old..and delete all date from Table 1 that is greater than 30 days.
    currently..I'm doing three process
    1) get all row that is greater than 30 days  
        "SELECT * FROM Table1 WHERE TO_DAYS(NOW()) - TO_DAYS(dateField) > 30"
    2) insert data into Table2
        while (res.hasNext())
              TableData data = ..... // .get row
              dataList.add(data);
              for (int i = 0; i < dataList.size(); i++){
                    pstm.setString.....
                    pstm.addBatch()
              pstm.executeBatch();
    3) delete data from Table1
        "DELETE FROM Table 1 WHERE  TO_DAYS(NOW()) - TO_DAYS(dateField) > 30"

    for this app..losing a few rows does not
    impact on how we analyze the data.That's what everyone always tells me too. But 99% of the time they come back and want to know why the cannot balance and/or validate the data between two runs taken only minutes from each other.
    I've seen people puzzle over data for days that they swear they ran the exact same utility for their tests, but they were in fact using live data, and additional data had accrued but since all they had to do was execute the a script without parameters (they didn't put in a stop time), they got two different answers and it always, and I mean always confuses people. Be safe, and put the option in for and end date/time, then when they waste days trying to figure out why the two different observations gave them different numbers, they cannot blame you (because you gave them the option)!
    My 2 cents for the day...

  • Read data from ODS table using value mapping

    hi all;
    can anyone help on how to read data from ODS table using value mapping

    Mudit,
    Take a look at this blog,
    <a href="/people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler">DB Lookup in Mapping</a>
    Regards,
    Bhavesh

  • Select max date from a table with multiple records

    I need help writing an SQL to select max date from a table with multiple records.
    Here's the scenario. There are multiple SA_IDs repeated with various EFFDT (dates). I want to retrieve the most recent effective date so that the SA_ID is unique. Looks simple, but I can't figure this out. Please help.
    SA_ID CHAR_TYPE_CD EFFDT CHAR_VAL
    0000651005 BASE 15-AUG-07 YES
    0000651005 BASE 13-NOV-09 NO
    0010973671 BASE 20-MAR-08 YES
    0010973671 BASE 18-JUN-10 NO

    Hi,
    Welcome to the forum!
    Whenever you have a question, post a little sample data in a form that people can use to re-create the problem and test their ideas.
    For example:
    CREATE TABLE     table_x
    (     sa_id          NUMBER (10)
    ,     char_type     VARCHAR2 (10)
    ,     effdt          DATE
    ,     char_val     VARCHAR2 (10)
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('15-AUG-2007', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('13-NOV-2009', 'DD-MON-YYYY'), 'NO');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('20-MAR-2008', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('18-JUN-2010', 'DD-MON-YYYY'), 'NO');
    COMMIT;Also, post the results that you want from that data. I'm not certain, but I think you want these results:
    `    SA_ID LAST_EFFD
        651005 13-NOV-09
      10973671 18-JUN-10That is, the latest effdt for each distinct sa_id.
    Here's how to get those results:
    SELECT    sa_id
    ,         MAX (effdt)    AS last_effdt
    FROM      table_x
    GROUP BY  sa_id
    ;

  • Pls Help me with steps to add data from xml file to SAP B1 through B1iSN.

    Pls Help me with steps to add data from xml file to SAP B1 through B1iSN. I  am getting stuck in xsl transformation. not able to understand where the mapping code needs to be added.
    Pls explain me the steps for adding data from xml to B1 quotation step by step.
    thanks and regards
    Priya

    Hi,
    Have you checked this: https://sap.na.pgiconnect.com/p45508295/?launcher=false&fcsContent=true&pbMode=normal ?
    Thanks,
    Gordon

  • Pls help : How To select fields and data from user_table for each tablename

    Please help with the query to generate a output which selects the code,meaning,inuse for each table in the user_table that has "CODED" as a part of table name.
    User table has some 800 table that contains CODED in the tablename.
    Desc of the table:
    DESCPTION:
    Name Null? Type
    SHORT_NAME NOT NULL VARCHAR2(20)
    CODE NOT NULL VARCHAR2(4)
    MEANING NOT NULL VARCHAR2(240)
    IN_USE VARCHAR2(1)
    NOTES VARCHAR2(2000
    UNITS NOT NULL VARCHAR2(1)
    AMOUNT NOT NULL VARCHAR2(3)
    CONVERTED VARCHAR2(1)
    RUN_NAME VARCHAR2(30)
    But all the table have code, meaning,in_use fields.
    O/P format :
    TABLE_NAME CODE MEANING IN_USE
    Help me pls.

    Not 100% sure what you want. If you want to see all the tables that have all three of those columns, then you could do something like:
    SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
    FROM user_tab_columns
    WHERE column_name = 'CODE' and
          table_name like '%CODED%'
    INTERSECT
    SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
    FROM user_tab_columns
    WHERE column_name = 'MEANING' and
          table_name like '%CODED%'
    INTERSECT
    SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
    FROM user_tab_columns
    WHERE column_name = 'INUSE' and
          table_name like '%CODED%'If you want to select those three columns from each of the tables, then you could do something like this.
    Create a command file called, for example, makesel.sql that looks like:
    SET PAGES 0 lines 500 trimspool on feedback off;
    spool sel.sql;
    prompt spool selout.txt;
    SELECT 'SELECT '''||table_name||''', code, meaning, in_use FROM '||
           table_name||';'
    FROM (SELECT table_name
          FROM user_tab_columns
          WHERE column_name = 'CODE' and
                table_name like '%CODED%'
          INTERSECT
          SELECT table_name
          FROM user_tab_columns
          WHERE column_name = 'MEANING' and
                table_name like '%CODED%'
          INTERSECT
          SELECT table_name
          FROM user_tab_columns
          WHERE column_name = 'INUSE' and
                table_name like '%CODED%')
    prompt 'spool off;'
    spool off;
    @sel.sqlAt the sqlplus prompt run the file using @makesel.sql. This will create another file called sel.sql containing the commands to select those three columns from each table that has all three columns, then after the new file is created, it runs the file (@sel.sql). The output will be spooled to a file called selout.txt.
    HTH
    John

  • Select data from a table and a view: field with same content and different type

    hi all,
    I need data from a table hrp1001 and a view V_USR_NAME. What they have in common are the content of the fields SOBID and BNAME .
    It will be easier if those fields add a same type but they dont.
    Any suggestions for a workaround?
    Thanks

    Hi Ramesh,
    Specify the date format as YYYYMMDD in where condition.
    Dates are internally stored in SAP as YYYYMMDD only.
    Change your date format in WHERE condition as follows.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and bdatu = <b>'99991231'.</b>
    I doubt check your data base table EQUK on this date for the existince of data.
    Otherwise, just change the conidition on BDATU like below to see all entries prior to this date.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and <b> bdatu <= '99991231'.</b>
    Thanks,
    Vinay
    Thanks,
    Vinay

  • Facing Problem with Select-options input data......help me?

    I have a select-options on my selection screen. In the database table i have different four values for this. ex EEX01, EEX02, EEX03 and EEX04.
    their overall names are DE, HE, IT, TR respectively.
    Now the requirement is user will enter this data like DE to TR , i am now confused how do convert these value to the values that i have in table. Because i have to use this for extracting the data from database table.
    thanks in advance.

    hi,
    what is the table name for the case.
    and jsut list what are the fields .. we'll try to map the same and see if it works..
    if for the field there is a check table attached then conversion routine will take care of that .
    just check on the field of the domain  in the dbtable
    like matn1 for dataelement matnr and domain matnr in mara table.
    regards,
    vijay

Maybe you are looking for

  • Please help me with this very basic question!

    Hi all, I m new to O/R mapping framework, my question is quite simple. Is iBatis an Object Relational Mapping technique? If it is, which one is better, iBatis or OJB? Thank your for your help! best regards

  • Custom table Not deleting the line items on the order.

    Hi All I have an issue, In SAP  we have created a custom table which is related to ship to party, as and when we delete any line items in the order(VBAP)  it should update /delete the custom table but it is not deleting, while when we create any line

  • Actiontec wireless router and my Airport Express?

    Can I get them to link together? I recentely switched to a Fiber Optic service which provided this Actiontec wireless router I believe it's model # MI 424 WR

  • Want to transfer data to another cpu

    got a new computer, want to transfer data from this computer to the new one i proceeded to sync up - created an account (on this computer not the new one) the new computer is asking for the code number from this computer but i am not able to find tha

  • New Financial Year -G/L Determination

    Hi All, It is observed that G/L determination accounts are missing when we set new financial year and set the document series accordingly. Why this happens even though it is the same company (database). Is it necessary to do the G/L determination eac