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

Select maximum value of Sequence Number for particular


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

New User


Joined: 16 Jun 2009
Posts: 1
Location: Chennai

PostPosted: Fri Jan 31, 2014 8:11 am
Reply with quote

Hi,
I am looking for a query which selects the maximum value of sequence number for various file id Prefix.

Here is the query which I have written but I its not working. Could some one please help me in resolving this issue?

SELECT A.FILE_TYPE
,A.FILE_ID_SUFFIX
,A.RUN_DATE_TIME
,A.FILE_SEQ_NUMBER
,A.FILE_DESCRIPTION
,A.TRANSFER_DATE_TIME
,A.TRANSFR_RESULT_IND
A.RECORD_COUNTER
FROM DPAXGA3.TAX523 A
INNER JOIN
( SELECT MAX(FILE_SEQ_NUMBER) MAX_SEQ_NUM, FILE_ID_SUFFIX
FROM DPAXGA3.TAX523
WHERE FILE_TYPE = 'SHEC'
AND FILE_ID_SUFFIX IN ('030','004','025')
GROUP BY FILE_ID_SUFFIX
) B ON A.FILE_TYPE = 'SHEC'
AND A.FILE_ID_SUFFIX = B.FILE_ID_SUFFIX
AND A.FILE_SEQ_NUMBER = B.MAX_SEQ_NUM
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Jan 31, 2014 1:32 pm
Reply with quote

Vijayshyale wrote:
... its not working. ... this issue ...

Not exactly the best description. What's the problem ?
Syntax error ?
no results ?
wrong results ?
time-out or locking problem ?

but anyhow : the psychic force is strong today and here's A solution for AN issue.
Code:
SELECT A.FILE_TYPE                                           
      ,A.FILE_ID_SUFFIX                                       
      ,A.RUN_DATE_TIME                                       
      ,A.FILE_SEQ_NUMBER                                     
      ,A.FILE_DESCRIPTION                                     
      ,A.TRANSFER_DATE_TIME                                   
      ,A.TRANSFR_RESULT_IND                                   
      ,A.RECORD_COUNTER                                       
 FROM DPAXGA3.TAX523 A                                       
WHERE A.FILE_TYPE      = 'SHEC'                               
  AND A.FILE_ID_SUFFIX IN ('030','004','025')                 
  AND A.FILE_SEQ_NUMBER = ( SELECT MAX(FILE_SEQ_NUMBER)       
                     FROM DPAXGA3.TAX523 B                   
                    WHERE B.FILE_TYPE      = A.FILE-TYPE     
                      AND B.FILE_ID_SUFFIX = A.FILE_ID_SUFFIX)
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 Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Generate random number from range of ... COBOL Programming 3
No new posts Increase the number of columns in the... IBM Tools 3
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top