IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to get the 5th record ?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
webxpertin
Warnings : 1

New User


Joined: 05 Apr 2005
Posts: 9
Location: india

PostPosted: Wed Jul 20, 2005 12:45 pm
Reply with quote

How to get the 5th record from a DB2 table or a 100th record from a vsam file directly without knowing any key of that particular record?
Thanks
Back to top
View user's profile Send private message
Abirami.YN

New User


Joined: 16 Jul 2005
Posts: 15
Location: India - Chennai

PostPosted: Wed Jul 20, 2005 7:25 pm
Reply with quote

Hi,

Try the following in DB2

SELECT *
FROM (SELECT
ROW_NUMBER() OVER (ORDER BY empno ASC) AS rownumber,
empno, firstnme
FROM edwarde.employee
) AS foo
WHERE rownumber = 5;

After executing this query , tell me ur result (I am not sure)
Back to top
View user's profile Send private message
shobam

New User


Joined: 18 Jul 2005
Posts: 34
Location: CN

PostPosted: Fri Jul 22, 2005 12:33 pm
Reply with quote

You can find the Nth record or a range of records from a table using the ROW_NUMBER as abirami mentioned.

To know about ROW_NUMBER go thru

www.cis.unisa.edu.au/oracle/server.101/b10759/functions122.htm

Good Example is available in

blogs.conchango.com/jamiethomson/archive/2005/02/16/1025.aspx
Back to top
View user's profile Send private message
Gops

New User


Joined: 21 Jul 2005
Posts: 23

PostPosted: Fri Jul 29, 2005 5:06 pm
Reply with quote

Hi Guys,

Tried with both of your examples,
but I am getting a syntax error on the over clause of the query.

Cheers,
Gopal
Back to top
View user's profile Send private message
vasudev9

New User


Joined: 02 Aug 2005
Posts: 1
Location: india

PostPosted: Tue Aug 02, 2005 8:24 pm
Reply with quote

How to get the 5th record from a DB2 table or a 100th record from a vsam file directly without knowing any key of that particular record?

Hi

To get 100th record from a vsam file, try this in IDCAMS

REPRO -
INFILE(DD1) -
OUTFILE(DD2) -
SKIP(99) -
COUNT(1)

This example SKIPS 99 Records and copies next 1 record.

Hope this do..

vasudev
Back to top
View user's profile Send private message
withnams

New User


Joined: 06 Jul 2005
Posts: 26
Location: Chennai

PostPosted: Wed Aug 03, 2005 2:10 pm
Reply with quote

It depends upon the version of the DB2 you are using?
Back to top
View user's profile Send private message
vijayamadhuri

Active User


Joined: 06 Apr 2005
Posts: 180

PostPosted: Fri Aug 05, 2005 3:20 am
Reply with quote

to obtain the 5 th record use the following

EXEC SQL FETCH ABSOLUTE +5 C1 INTO :HVDEPTNO, :DEPTNAME, :MGRNO;

To fetch the fifth row from the end of the result table, use this FETCH statement:
EXEC SQL FETCH ABSOLUTE -5 C1 INTO :HVDEPTNO, :DEPTNAME, :MGRNO;

In this way u can fetch any row u require
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
Search our Forums:

Back to Top