MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

unload first 10 rows only

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Mon Aug 27, 2007 2:01 pm    Post subject: unload first 10 rows only Reply with quote

Members,

I am trying to unload records from a DB2 table using a query in JCL by executing Unload utility , but i am getting many records , however i want to restrict the unload to only first 10 rows only , can somebody help me with the query ?

one option would be to unload and then run a sort step to copy first 10 records using different ways but i would like to have it done by a sql query.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Aug 27, 2007 2:13 pm    Post subject: Reply with quote

yadav2005,

If your shop has DB2 version 7 and higher then you can use the FETCH FIRST N rows clause like shown below


Code:

 SELECT *
   FROM TABLE
  FETCH FIRST 10 ROWS ONLY;


Check this link for a detailed explanation of the clause

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQJ12/4.4.3

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Mon Aug 27, 2007 2:26 pm    Post subject: Reply with quote

Thanks Kolusu for your needful help it works .But i would like to have a WHERE condition included also in the query , if that is the case how should i use.

For example:
Code:

SELECT *
   FROM TABLE
  FETCH FIRST 10 ROWS ONLY;

Now i want to include a condition where EMPAGE = 24 , how can i do that as i want to retreive first 10 employees whose EMPGAE = 24 years.
Back to top
View user's profile Send private message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Mon Aug 27, 2007 2:27 pm    Post subject: Reply with quote

Kolusu,

I got the solution by trying:
Code:

SELECT *
   FROM TABLE
  WHERE EMPAGE = 24
  FETCH FIRST 10 ROWS ONLY;
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group