Hi All,
I need to know whether the Order By clause can be used in singleton select.
SELECT CUST_NMBR, LAST_UPDT_DT
INTO :WS-CUST-NMBR,:WS-LAST-UPDT
FROM CUST
WHERE END_DT >= :WS-PARM-DATE
AND EFF_DT <= :WS-PARM-DATE
ORDER BY LAST_UPDT_DT DESC
FETCH FIRST 1 ROW ONLY
the above was the query I wanted to execute in singleton mode. If I compile the program, I am getting ' ORDER BY NOT PERMITTED' error. Can any one suggest me what can be done for this requirement.
Thanks in advance...
Order By Clause in Singleton Select
-
- Posts: 6
- Joined: Wed Jun 17, 2009 3:09 pm
- Skillset: JCL,COBOL,NATURAL,VSAM,DB2,CICS
- Referer: Google
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Order By Clause in Singleton Select
Hello and welcome to the forum,
What happens if you run this query in spufi using literals instead of host variables?
What happens if you run this query in spufi using literals instead of host variables?
Hope this helps,
d.sch.
d.sch.
- swd
- Posts: 109
- Joined: Wed Feb 18, 2009 9:18 pm
- Skillset: COBOL, DB2, JCL, REXX, ISPF, IBM Utility Programs, Performance Tuning and Benchmarking
- Referer: Google Search
- Location: UK
Re: Order By Clause in Singleton Select
Why not remove the ORDER BY - you don't need it!
-
- Posts: 6
- Joined: Wed Jun 17, 2009 3:09 pm
- Skillset: JCL,COBOL,NATURAL,VSAM,DB2,CICS
- Referer: Google
Re: Order By Clause in Singleton Select
Hi,
1. This query works fine in SPUFI. I tried this before coming into this forum itself.
2. I need Order By here, because i want the LAST_UPDT_DT to be latest.
then I tried using Sub-query. But its taking more CPU time when compared to the pgm which is using cursor for the same query...
Please help me out to avoid cursor for this query...
1. This query works fine in SPUFI. I tried this before coming into this forum itself.
2. I need Order By here, because i want the LAST_UPDT_DT to be latest.
then I tried using Sub-query. But its taking more CPU time when compared to the pgm which is using cursor for the same query...
Please help me out to avoid cursor for this query...
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Order By Clause in Singleton Select
Hello,
Why might you believe this?Why not remove the ORDER BY - you don't need it!
Keep in mind that spufi generates a cursor "under the covers". . .This query works fine in SPUFI. I tried this before coming into this forum itself.
Hope this helps,
d.sch.
d.sch.
-
- Posts: 6
- Joined: Wed Jun 17, 2009 3:09 pm
- Skillset: JCL,COBOL,NATURAL,VSAM,DB2,CICS
- Referer: Google
Re: Order By Clause in Singleton Select
Hi,
Why not remove the ORDER BY - you don't need it!
Why might you believe this?
I should use ORDER BY here, then only I can get the Latest ( updated ) customer.
This query works fine in SPUFI. I tried this before coming into this forum itself.
Keep in mind that spufi generates a cursor "under the covers". . .
I really don't understand this
Thanks
And a change in the query, ( I missed this last time. sorry...)
SELECT CUST_NMBR, LAST_UPDT_DT
INTO :WS-CUST-NMBR,:WS-LAST-UPDT
FROM CUST
WHERE CUST_LOC_NMBR = :WS-CUST-LOC-NMBR
AND END_DT >= :WS-PARM-DATE
AND EFF_DT <= :WS-PARM-DATE
ORDER BY LAST_UPDT_DT DESC
FETCH FIRST 1 ROW ONLY
Why not remove the ORDER BY - you don't need it!
Why might you believe this?
I should use ORDER BY here, then only I can get the Latest ( updated ) customer.
This query works fine in SPUFI. I tried this before coming into this forum itself.
Keep in mind that spufi generates a cursor "under the covers". . .
I really don't understand this
Thanks
And a change in the query, ( I missed this last time. sorry...)
SELECT CUST_NMBR, LAST_UPDT_DT
INTO :WS-CUST-NMBR,:WS-LAST-UPDT
FROM CUST
WHERE CUST_LOC_NMBR = :WS-CUST-LOC-NMBR
AND END_DT >= :WS-PARM-DATE
AND EFF_DT <= :WS-PARM-DATE
ORDER BY LAST_UPDT_DT DESC
FETCH FIRST 1 ROW ONLY
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Order By Clause in Singleton Select
Hello,
You mentioned that you want to avoid using a cursor in your code. To be sure that your process always works correctly, i believe you need the cursor. The spufi query that does work uses a cursor.
Where is "I am getting ' ORDER BY NOT PERMITTED' error. " shown? What is the message id?
SPUFI runs with a cursor internally. . .I really don't understand this
You mentioned that you want to avoid using a cursor in your code. To be sure that your process always works correctly, i believe you need the cursor. The spufi query that does work uses a cursor.
Where is "I am getting ' ORDER BY NOT PERMITTED' error. " shown? What is the message id?
Hope this helps,
d.sch.
d.sch.
-
- Posts: 6
- Joined: Wed Jun 17, 2009 3:09 pm
- Skillset: JCL,COBOL,NATURAL,VSAM,DB2,CICS
- Referer: Google
Re: Order By Clause in Singleton Select
Hi,
Where is "I am getting ' ORDER BY NOT PERMITTED' error. " shown? What is the message id?
This I got while compiling the Application program.below is the error message,
DSNH109I E DSNHAPLY LINE 57 COL 38 "ORDER BY" CLAUSE NOT PERMITTED
I have the cursor for this already. So far, I tried to avoid the cursor for this. But you mean to say that I should use a cursor for this right?
Where is "I am getting ' ORDER BY NOT PERMITTED' error. " shown? What is the message id?
This I got while compiling the Application program.below is the error message,
DSNH109I E DSNHAPLY LINE 57 COL 38 "ORDER BY" CLAUSE NOT PERMITTED
I have the cursor for this already. So far, I tried to avoid the cursor for this. But you mean to say that I should use a cursor for this right?
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Order By Clause in Singleton Select
Hello,
In front of this "DSNH109I", is there an IGYxxxx message id?
What version of db2 is used on your system? Which version of COBOL?
In front of this "DSNH109I", is there an IGYxxxx message id?
I believe so.But you mean to say that I should use a cursor for this right?
What version of db2 is used on your system? Which version of COBOL?
Hope this helps,
d.sch.
d.sch.
- swd
- Posts: 109
- Joined: Wed Feb 18, 2009 9:18 pm
- Skillset: COBOL, DB2, JCL, REXX, ISPF, IBM Utility Programs, Performance Tuning and Benchmarking
- Referer: Google Search
- Location: UK
Re: Order By Clause in Singleton Select
After reading this post properly (!) you can't have an order by because (accoring to Quick Reference)
So, Dick is correct you will need a Cursor as you are doing a SELECT INTO. This way you can have the ORDER BY.
But.... have you tried SELECT CUST_NMBR, MAX(LAST_UPDT_DT) and remove the ORDER BY, this way you'll get the latest last update date without a cursor. See if that works.
Code: Select all
DSNH109I E csectname LINE nnnn COL cc type CLAUSE NOT PERMITTED
Explanation: The type is INTO, ORDER BY, FOR UPDATE, , USING, LARGE, or
CORRELATION NAME.
o A SELECT INTO statement cannot include ORDER BY, because the result
cannot be more than a single row.
So, Dick is correct you will need a Cursor as you are doing a SELECT INTO. This way you can have the ORDER BY.
But.... have you tried SELECT CUST_NMBR, MAX(LAST_UPDT_DT) and remove the ORDER BY, this way you'll get the latest last update date without a cursor. See if that works.
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Pass PARM from JCL to Easytrieve SQL WHERE clause
by MemoPerez » Tue Oct 24, 2023 8:32 am » in CA-Easytrieve - 2
- 3123
-
by MemoPerez
View the latest post
Fri Oct 27, 2023 1:13 am
-