|
View previous topic :: View next topic
|
| Author |
Message |
Raymond Sachs
New User
Joined: 13 Dec 2007 Posts: 45 Location: USA
|
|
|
|
Dear Listers,
What am I doing wrong? How do I go about it? We are in zOS V8
I get an SQL ERROR on the following:
| Code: |
SELECT KEY1, COL1, COL2, COL3
FROM TAB1
WHERE COL1 = :HOSTVAR01
AND COL2 = ( SELECT C22 FROM TAB2
WHERE KEY1= FKEY1
ORDER BY LST_UPDT_DT DESC, LST_UPDT_TM DESC
FETCH FIRST 1 ROW ONLY)
|
Requirement:
SELECT KEY1, COL1, COL2, COL3
FROM TAB1
WHERE COL1 = :H
AND COL2 = ("Most recent value of C22 from table: TAB2)
Table TAB2 has columns FKEY1, C11, C22, C33, LST_UPDT_DT, LST_UPDT_TM |
|
| Back to top |
|
 |
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
| What sql code are you getting? |
|
| Back to top |
|
 |
Raymond Sachs
New User
Joined: 13 Dec 2007 Posts: 45 Location: USA
|
|
|
|
| Am trying to test run in QMF and it errors out at the ORDER BY line. I reckon I can use an ORDER BY in subquery. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| And the answer to Craq's question is.... |
|
| Back to top |
|
 |
dick scherrer
Moderator Emeritus

Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
I suspect there is no run-time "error" - i suspect there is a syntax error that prevents execution.
| Quote: |
| I reckon I can use an ORDER BY in subquery. |
If i understand the initial post, it sounds like db2 v8 (not zos v8) is being used. I don't remember if this available in db2 v8, but the manual for v8 should have the specifics. |
|
| Back to top |
|
 |
dbzTHEdinosauer
Global Moderator

Joined: 20 Oct 2006 Posts: 6965 Location: porcelain throne
|
|
|
|
| or it could be the FETCHing phrase |
|
| Back to top |
|
 |
|
|