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 

Error:"ORDER BY" CLAUSE NOT PERMITTED

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


Joined: 05 Jun 2004
Posts: 46
Topics: 18

PostPosted: Sat Jul 10, 2004 4:37 am    Post subject: Error:"ORDER BY" CLAUSE NOT PERMITTED Reply with quote

Hi,
I've following query in my COBOL-DB2 program.

EXEC SQL
SELECT COUNT(*)
INTO :WS-GLSSVLD1-CO-DES-CNT
FROM TABLE_NAME
GROUP BY SYS_ID
ORDER BY 1 DESC
FETCH FIRST 1 ROWS ONLY
END-EXEC.

wherein the variable in bold is declared in working storage and I'm using it as host variable.

It gives me the following error during compilation:
"ORDER BY" CLAUSE NOT PERMITTED Sad
I executed same query in spuffi(of course,after removing INTO clause) and that gave me the output without any error.

So,any idea about possible reasons of getting the error in the COBOL-DB2 program? Is it because of the INTO clause ? Shocked
Thanks in advance.
_________________
Regards,
Mangsk
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Sun Jul 11, 2004 10:35 pm    Post subject: Reply with quote

Mangsk,

You cannot have an ORDER by Clause with FETCH FIRST clause unless you define it as a cursor. so define a cursor for the sql statement and you should not have any problem.

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
Cathygomez
Beginner


Joined: 04 Aug 2004
Posts: 6
Topics: 3

PostPosted: Thu Aug 19, 2004 1:06 am    Post subject: Reply with quote

mangsk,
Try this,
EXEC SQL
SELECT COUNT(*)
INTO :WS-GLSSVLD1-CO-DES-CNT
FROM TABLE_NAME
GROUP BY SYS_ID
FETCH FIRST 1 ROWS ONLY
ORDER BY 1 DESC
END-EXEC.

Here ORDER BY Clause comes next to FETCH
Back to top
View user's profile Send private message
CZerfas
Intermediate


Joined: 31 Jan 2003
Posts: 211
Topics: 8

PostPosted: Thu Aug 19, 2004 6:19 am    Post subject: Reply with quote

Using a singleton select instead of defining a cursor means, that youn KNOW, that there is only one row qualifying for your query. Why would you want to sort?

Issuing that singleton select from Spufi means, that the Spufi program turns your select statement into a cursor definition and executes it. Therefor ordering is possible.

regards
Christian
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