How about this?
(I don't know about performance.)
SELECT D.Supplier, C.Gadget_QTY, D.SEQNO
INTO :Supplier
, :Gadget_QTY
, :SEQNO
FROM DS.Supplier D
INNER JOIN
DS.Supplier_CPCTY C
ON D.Supplier = C.Supplier
AND C.PROD_NUM = :PROD_NUM
WHERE D.SEQNO > :SEQNO /* ie. GT the previous Seqno */
AND D.SEQNO
= (SELECT MIN(Dm.SEQNO)
FROM DS.Supplier Dm
INNER JOIN
DS.Supplier_CPCTY Cm
ON Dm.Supplier = Cm.Supplier
AND Cm.PROD_NUM = :PROD_NUM
WHERE Dm.SEQNO > :SEQNO
)
;
If only one matching DS.Supplier_CPCTY for each DS.Supplier is always
exists,
The query could be simplified a little.
SELECT D.Supplier, C.Gadget_QTY, D.SEQNO
INTO :Supplier
, :Gadget_QTY
, :SEQNO
FROM DS.Supplier D
INNER JOIN
DS.Supplier_CPCTY C
ON D.Supplier = C.Supplier
AND C.PROD_NUM = :PROD_NUM
WHERE D.SEQNO > :SEQNO /* ie. GT the previous Seqno */
AND D.SEQNO
= (SELECT MIN(Dm.SEQNO)
FROM DS.Supplier Dm
WHERE Dm.SEQNO > :SEQNO
)
;
>> Interestingly enough, I can execute the Select with Order By and Fetch First 1 Rows Only in SPUFI, with no problem. <<
In DB2 UDB for OS/390 and z/OS SQL Reference Version 7
Chapter 4. Queries -> select-statement
Both order-by-clause and fetch-first-clause can be specified.
Chapter 5. Statements -> SELECT INTO
Only FETCH FIRST [1] ROW ONLY can be specified.
becoolmun@yahoo.com - 29 Sep 2005 21:22 GMT
Thanks, Tonkuma!
I wasn't able to use your suggestion quite as provided, I was able to
break it up into two queries. the first one just gets the next
sequence number and then I just plug it in the second query as an "="
predicate.
I read the DB2 manual chapters you refer to, but the Select with "INTO"
does not allow "ORDER BY" period. And I can't think of anyway to
receive the table values without an "INTO", so I can't use "ORDER BY"
or "FIRST ROW ONLY".
I believe I read that V8 may support this, which doesn't help me at the
moment.
Thanks again!
> How about this?
> (I don't know about performance.)
[quoted text clipped - 47 lines]
> Chapter 5. Statements -> SELECT INTO
> Only FETCH FIRST [1] ROW ONLY can be specified.
Robert - 29 Sep 2005 22:44 GMT
> Thanks, Tonkuma!
> I wasn't able to use your suggestion quite as provided, I was able to
[quoted text clipped - 62 lines]
> > Chapter 5. Statements -> SELECT INTO
> > Only FETCH FIRST [1] ROW ONLY can be specified.
I haven't used DB2 for quite a while now, but seem to remember using
GROUP BY and HAVING to fiddle sequencing when ORDER BY was not allowed.
Might be worth a try.
Robert