Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Unanswered: how to create temporary table in db2 v8 in os390

    sno acco_no amount

    1 50001 5000
    2 50002 4000
    3 50001 2500
    4 50002 3100
    5 50002 3400
    6 50001 1500

    inwhich i want to take 50001's last 2 records one by one.

    ie is result :

    sno acco_no amount
    6 50001 1500-----> i want to move this record to variable1
    3 50001 2500-----> i want to move this record to variable2

    pl help me anyone
    Last edited by maheshabo; 03-13-11 at 04:41.

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    What error messages did you got?
    Please copy and paste all related messages.

  3. #3
    Join Date
    Mar 2011
    Posts
    2
    sno eno salary

    1 e01 50000
    2 e02 6000
    3 e01 400
    4 e02 8000
    5 e01 5000
    6 e02 7500

    i want to selct e02's last 3 records(transaction) & i want to display those 3 records in map(cics).

    im sure thst to select more than 1 record v ve to use cursor.but if i select those records how to move those values to map.

    i used following query in spufi

    1.select salary from Table_name order by sno desc where eno='e02'

    eventho i cudn fetch.. pl help me

  4. #4
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Your true issue was not clear for me.

    You asked similar, but different questons on your first and second posts.

    inwhich i want to take 50001's last 2 records one by one.
    i want to selct e02's last 3 records(transaction) & i want to display those 3 records in map(cics).
    Anyhow, you can select last <n> rows by combination of "ORDER BY ... DESC" and "FETCH FIRST <n> ROWS ONLY", like ...
    SELECT amount FROM ... WHERE acco_no = 50001 ORDER BY sno DESC FETCH FIRST 2 ROWS ONLY;
    or
    SELECT salary FROM ... WHERE eno = 'e02' ORDER BY sno DESC FETCH FIRST 3 ROWS ONLY;


    If you used cursor, "FETCH FIRST <n> ROWS ONLY" might be unnecessary.
    sno acco_no amount
    6 50001 1500-----> i want to move this record to variable1
    3 50001 2500-----> i want to move this record to variable2
    Declare cursor, OPEN cursor then repeat two FETCH statements, like...
    FETCH ... INTO variable1;
    FETCH ... INTO variable2;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •