Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Help on Query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Help on Query
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    Post subject:
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Sat Mar 31, 2012 1:32 pm    Post subject: Reply to: Help on Query
Reply with quote

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

Site Director


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

PostPosted: Sun Apr 01, 2012 2:53 am    Post subject:
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: 6970
Location: porcelain throne

PostPosted: Sun Apr 01, 2012 5:27 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts reg query on DYNALLOC feature raghuraman123 SYNCSORT 12 Wed Jan 10, 2018 2:42 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us