MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SQL Query

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Mon Apr 26, 2004 9:27 am    Post subject: SQL Query Reply with quote

Code:

col1------------col2-----Col3---col4------col5---col6-----col7

260071311------ FR------ N------3AA2------2------3AA------27.02.2004
260071311------ FR------ N------3AA2------2------3AA------03.12.2003
261587935------ FR------ N------4A 1------1------4A-------22.04.2004
261587935------ FR------ N------4A 1------1------4A-------21.04.2004
263267841------ FR------ N------A 1------1------A--------01.04.2004
263267841------ FR------ N------A 1------1------A--------26.03.2004

Required O/P:
I want to select the whole row with second highest date .
How can I do this...
Code:

260071311------ FR------ N------3AA2------2------3AA------03.12.2003

261587935------ FR------ N------4A 1------1------4A-------21.04.2004

263267841------ FR------ N------A 1------1------A--------26.03.2004
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Mon Apr 26, 2004 9:46 am    Post subject: Reply with quote

Paneendra V K,

Which column in the above data depicts the rate?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Mon Apr 26, 2004 9:47 am    Post subject: Reply with quote

7th cloumn Kolusu.
Back to top
View user's profile Send private message Send e-mail
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Mon Apr 26, 2004 9:50 am    Post subject: Reply with quote

Actually there are so many rows present in the table.
I am using Cursor to do this.

Could you please give me the syntax using Cursor ..........
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Mon Apr 26, 2004 9:50 am    Post subject: Reply with quote

Paneedra vk,

7th column looks like a date column. What is the definition of the column? Is it defined as date? And the format also looks different . Is there an embedded decimal point in the data?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Mon Apr 26, 2004 9:55 am    Post subject: Reply with quote

Name Coltype Length

CRH_ALG_RUN_DT DATE 4
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Mon Apr 26, 2004 10:01 am    Post subject: Reply with quote

Vkphani,

The date field length is 4? How is that possible? Any column which is defined as date is 10 bytes in length. Can you clarify?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Mon Apr 26, 2004 10:03 am    Post subject: Reply with quote

Sorry,
The length is 10.
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Mon Apr 26, 2004 10:37 am    Post subject: Reply with quote

Vkphani,

The simlest way to do this is adding an order by clause with select. Since you are using a cursor to fetch the rows we can filter the rows

Code:

W-STORE-KEY         PIC X(10) VALUE SPACES.

EXEC SQL

     DECLARE PHANI_CSR CURSOR FOR
             SELECT * FROM PHANI   
             ORDER BY COL1,COL7 DESC
END-EXEC

PROCEDURE DIVISION.

   
EXEC SQL                   
    OPEN PHANI_CSR        
END-EXEC         

EXEC SQL                       
    FETCH PHANI_CSR         
    INTO :TABLE.COL1       
        ,:TABLE.COL2   
        ,:TABLE.COL3   
        ,:TABLE.COL4   
        ,:TABLE.COL5   
        ,:TABLE.COL6   
        ,:TABLE.COL7   
END-EXEC           

EVALUATE SQLCODE
    WHEN +0
          IF W-STORE-KEY = COL1 OF TABLE
             CONTINUE
          ELSE
             PERFORM FETCH
             W-STORE-KEY = COL1 OF TABLE
          END-IF
    WHEN +100
          CLOSE THE CURSOR
               
END-EVALUATE



Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group