IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Help on Query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Raymond Sachs

New User


Joined: 13 Dec 2007
Posts: 45
Location: USA

PostPosted: Sat Mar 31, 2012 5:05 am
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Sat Mar 31, 2012 6:23 am
Reply with quote

What sql code are you getting?
Back to top
View user's profile Send private message
Raymond Sachs

New User


Joined: 13 Dec 2007
Posts: 45
Location: USA

PostPosted: Sat Mar 31, 2012 6:56 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Mar 31, 2012 1:32 pm
Reply with quote

And the answer to Craq's question is....
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Apr 01, 2012 2:53 am
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sun Apr 01, 2012 5:27 am
Reply with quote

or it could be the FETCHing phrase
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top