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: 7315

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: 6968
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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm

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