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

order by without cursor


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

New User


Joined: 24 Aug 2007
Posts: 38
Location: chennai

PostPosted: Thu Nov 22, 2007 5:08 pm
Reply with quote

Hi,

I want to get the minimum of the product_num from the below query,

SELECT PRODUCT_NUM,
FORM_TYPE,
CLAIMFACTS_IND,
INTO :ZN-PRODUCT-NUM,
:ZN-FORM-TYPE,
:ZN-CLAIMFACTS-IND,
FROM RATE_NETWORK
WHERE CARRIER = :ZN-CARRIER
AND STATE = :ZN-STATE
AND COUNTY = :ZN-COUNTY
AND PROD_TYPE = :ZN-PROD-TYPE
AND PROD_LINE = :ZN-PROD-LINE
ORDER BY PRODUCT_NUM

I am getting the error that "order by" cannot be used.

But when i am using min(product_num) and the group by clause the query is working, can someone please tell me why order by doesn't work without cursor.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Nov 22, 2007 6:11 pm
Reply with quote

need to have vsn 8 or better and use the fetch first row only clause for the order by to work.

if you are on vsn 7 or lower, you are out of luck.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Nov 22, 2007 6:14 pm
Reply with quote

Because if you have a scalar function MIN you are returning only one row. However once you take away that scalar, the return set is more than one row and COBOL can't handle that without a cursor.

To get the minimum, you don't even need to use the group by, you could get away with
Code:

SELECT MIN(Product_num)
FROM RATE_NETWORK
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Thu Nov 22, 2007 6:20 pm
Reply with quote

The query you designed, should always return single row. In that case, why do you need an ORDER BY clause.
Back to top
View user's profile Send private message
sanil m

New User


Joined: 24 Aug 2007
Posts: 38
Location: chennai

PostPosted: Thu Nov 22, 2007 6:34 pm
Reply with quote

thanx for the reply

@srihari

We are not sure we'll be getting single row or multiple rows.
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Thu Nov 22, 2007 6:51 pm
Reply with quote

Anil,
Then please make sure query always returns 1 row to avoid -811. Follow Steve's suggestion if it works for you.
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