View previous topic :: View next topic |
Author |
Message |
mangsk Beginner

Joined: 05 Jun 2004 Posts: 46 Topics: 18
|
Posted: Sat Jul 10, 2004 4:37 am Post subject: Error:"ORDER BY" CLAUSE NOT PERMITTED |
|
|
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
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 ?
Thanks in advance. _________________ Regards,
Mangsk |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Sun Jul 11, 2004 10:35 pm Post subject: |
|
|
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 |
|
 |
Cathygomez Beginner
Joined: 04 Aug 2004 Posts: 6 Topics: 3
|
Posted: Thu Aug 19, 2004 1:06 am Post subject: |
|
|
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 |
|
 |
CZerfas Intermediate
Joined: 31 Jan 2003 Posts: 211 Topics: 8
|
Posted: Thu Aug 19, 2004 6:19 am Post subject: |
|
|
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 |
|
 |
|
|