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

Order by in EMBEDDED SQL?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Vani venkateshmurthy

New User


Joined: 20 Nov 2004
Posts: 1

PostPosted: Sat Nov 20, 2004 11:19 am
Reply with quote

I am using an embedded SQL ( host language - COBOL) Query which has ORDER BY clause and FETCH WITH FIRST 1 ROW ONLY. When i run the query in QMF, it works fine. But it gives an error 'ORDER BY NOT PERMITTED' when the program is put for compilation. Can anyone explain why ORDER BY and FETCH WITH FIRST 1 ROW ONLY cannot be used together in Embedded SQL?
Back to top
View user's profile Send private message
janardhana Reddy

New User


Joined: 20 Oct 2004
Posts: 17
Location: Bangalore

PostPosted: Sat Nov 20, 2004 11:25 am
Reply with quote

You can use "optimize n rows". I forgot sybntax. You can refer book
Back to top
View user's profile Send private message
ksivapradeep

New User


Joined: 30 Jul 2004
Posts: 95

PostPosted: Wed Dec 08, 2004 4:36 pm
Reply with quote

hi ,

i think u have to put where clause ie.

SELECT * FROM TABLE-NAME WHERE FETCH FIRST N ROWS ONLY
regards,
siva pradeep
Back to top
View user's profile Send private message
ovreddy

Active User


Joined: 06 Dec 2004
Posts: 211
Location: Keane Inc., Minneapolis USA.

PostPosted: Wed Dec 08, 2004 5:34 pm
Reply with quote

Hi,

Both will work no problem. just use ORDER BY as a last clause that is after all other where predicates. Ok .

i.e.

select col1 from tab1 where fetch first 1 row only order by col1;
Back to top
View user's profile Send private message
richa gupta

New User


Joined: 29 Jul 2007
Posts: 8
Location: noida

PostPosted: Tue Oct 09, 2007 5:21 pm
Reply with quote

Hello,

I am getting same error as mentioned above by Vani. I am even getting the ORDER BY error if I comment out FETCH FIRST ONE 1 ROW ONLY. These are working fine when run in QMF. Please help.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Tue Oct 09, 2007 5:26 pm
Reply with quote

I know it's a dumb question, but what is the select and what is the error.....
Back to top
View user's profile Send private message
richa gupta

New User


Joined: 29 Jul 2007
Posts: 8
Location: noida

PostPosted: Tue Oct 09, 2007 5:34 pm
Reply with quote

I want to select rows in a cursor arranged on descending order of a field, which can be easily retrieved by ORDER BY clause.

I am getting this error:
"ORDER BY" CLAUSE NOT PERMITTED
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 Rotate partition-logical & physic... DB2 0
No new posts DB2 Load - Sort Or order BY DB2 1
No new posts GDG all in sequence order JCL & VSAM 9
No new posts Combining more 4 files with sorted or... DFSORT/ICETOOL 3
No new posts how to show listing in physical locat... PL/I & Assembler 2
Search our Forums:

Back to Top