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 

Can this be done throught SPUFI

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


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Fri May 11, 2007 7:25 am    Post subject: Can this be done throught SPUFI Reply with quote

Hi

I have a table EMP with columns EMP_NAME and EMP_SALARY,
I want to have a SQL query in SPUFI to get exactly 50th row of the table.
Is this possible in SPUFI or should I use cursors?. Can anybody please help me.
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Fri May 11, 2007 7:29 am    Post subject: Reply with quote

Do you mean the 50th row entered into the table or the 50th row that DB2 returns - they may not be the same. I would look at the syntax for SELECT and see if it has an option to return the nth row only (where n is greater than 1)
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri May 11, 2007 7:46 am    Post subject: Reply with quote

psmadhusudhan,

Try this

Code:

SELECT EMP_NAME
      ,EMP_SALARY                   
  FROM EMP A,                     
 TABLE (SELECT COUNT(*)+1 AS ROW#         
          FROM EMP B               
         WHERE B.EMP_NAME < A.EMP_NAME) AS TEMP_TAB   
WHERE ROW# = 50                           
  ;           



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
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Mon May 14, 2007 3:11 am    Post subject: Reply with quote

hi kolusu

I had tried with ur systax on my table as below
Code:

SELECT POL_POLICY_REF_S
  FROM NUDW6.TDWDPOL A
 TABLE (SELECT COUNT(*)+1 AS ROW#
          FROM NUDW6.TDWDPOL B
         WHERE B.POL_POLICY_REF_S < A.POL_POLICY_REF_S) AS TEMP_TAB
WHERE ROW# = 50
  ;

but I am getting sqlcode -199.
Could u please help me in this
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Mon May 14, 2007 3:16 am    Post subject: Reply with quote

What do your error messages say? Have you looked up -199? If you did you would undedrstand that perhaps you need to give more than just the error code.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon May 14, 2007 6:55 am    Post subject: Reply with quote

Quote:

but I am getting sqlcode -199.
Could u please help me in this


psmadhusudhan,

If you have compared the 2 sql's you would have found the mistake. you are missing a comma before the TABLE keyword (before the outer select). Add the comma and you should be fine

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


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Mon May 14, 2007 7:43 am    Post subject: Reply with quote

Kolusu

Thanks for correction. I have run sql after correcting but it is retrieving zero rows. My table consists of 2000 rows.
What might be the problem? I tried to retrieve 50th row. Please help me
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon May 14, 2007 8:25 am    Post subject: Reply with quote

psmadhusudhan,

Do you have any duplicates for POL_POLICY_REF_S ? Run this sql and check the row #

Code:

SELECT POL_POLICY_REF_S
      ,Row#
  FROM NUDW6.TDWDPOL A
 TABLE (SELECT COUNT(*)+1 AS ROW#
          FROM NUDW6.TDWDPOL B
         WHERE B.POL_POLICY_REF_S < A.POL_POLICY_REF_S) AS TEMP_TAB
  ;


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


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Tue May 15, 2007 1:14 am    Post subject: Reply with quote

Kolusu

Yes, I have duplicates for POL_POLICY_REF_S. The maximum value of row# i got is 3353.
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Thu May 17, 2007 3:34 am    Post subject: Reply with quote

Please help me in achieving this. Embarassed
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu May 17, 2007 8:10 am    Post subject: Reply with quote

Quote:

Please help me in achieving this


psmadhusudhan,

You are missing an important point here. Since your table has duplicates how would you have duplicate rows.

try this sql

Code:

SELECT POL_POLICY_REF_S
  FROM NUDW6.TDWDPOL A
 ,TABLE (SELECT COUNT(DISTINCT(POL_POLICY_REF_S)) + 1 AS ROW#
           FROM NUDW6.TDWDPOL B
          WHERE B.POL_POLICY_REF_S < A.POL_POLICY_REF_S) AS TEMP_TAB
  WHERE ROW# = 50                           
  FETCH FIRST 1 ROW ONLY
  ;


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
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Thu May 17, 2007 10:27 pm    Post subject: Reply with quote

Kolusu

Thanks for your help. Your code is fetching is 50th POL_POLICY_REF_S , but my intention is not that. I want to have the POL_POLICY_REF_S which is on 50th row. Means whatever POL_POLICY_REF_S might be there on 50th row it should be fetched.

And I want to have generic code such that even If I want to fetch complete row with all columns, the code should help me doing it. Means I want to have all the data on that exact row. Please help me in achieving this.
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Fri May 18, 2007 6:40 am    Post subject: Reply with quote

psmadhusudhan,

Quote:

Your code is fetching is 50th POL_POLICY_REF_S , but my intention is not that. I want to have the POL_POLICY_REF_S which is on 50th row. Means whatever POL_POLICY_REF_S might be there on 50th row it should be fetched.


what do you mean by the 50th row? DB2 is a relational database system. That means the rows fetched for a query are
  • related in some way - the conditions in your WHERE clause'
and
  • are either ordered - ORDER BY clause - or not
DB2 does not guarantee the same 'row order' each time, when there is no ORDER BY clause.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri May 18, 2007 7:52 am    Post subject: Reply with quote

psmadhusudhan wrote:
Kolusu

Thanks for your help. Your code is fetching is 50th POL_POLICY_REF_S , but my intention is not that. I want to have the POL_POLICY_REF_S which is on 50th row. Means whatever POL_POLICY_REF_S might be there on 50th row it should be fetched.

And I want to have generic code such that even If I want to fetch complete row with all columns, the code should help me doing it. Means I want to have all the data on that exact row. Please help me in achieving this.


psmadhusudhan,

Unless your table is defined to have rownum column, there is NO way you can retrieve the 50th row. I rarely ask the reason as to "why" you want to do this? What exactly is the requirement. I am baffled at the whole idea that there are specifications to get the 50th row.

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