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

Adding Rownum based on key in Colunmn!


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

New User


Joined: 18 Mar 2007
Posts: 44
Location: New Jersey,USA

PostPosted: Mon Feb 16, 2009 12:32 pm
Reply with quote

Hi,
I have been asked by my deployment team to write a query for this requirement.
sample I/P table:
Col1: col2:
aaaa1111 value1
aaaa1111 value2
aaaa1222 value1
aaaa1333 value1
aaaa1333 value2
aaaa1333 value3
aaaa1333 value4

Here as observed the COL1 has duplicate values and the O/P format they require is:
Row COL1 COL2
1 aaaa1111 value1
2 aaaa1111 value2
1 aaaa1222 value1
1 aaaa1333 value1
2 aaaa1333 value2
3 aaaa1333 value3
4 aaaa1333 value4

I.e They want the row number column to change in correpsondence with the COL1 and restart the value if the COL1 value changes.

I tried them contacting for the exact requirement, and they are yet to provide any inputs on that and they are persisting to go ahead with the exisitng problem statement !!

Can you Help?
Back to top
View user's profile Send private message
ykishor
Currently Banned

New User


Joined: 11 Aug 2007
Posts: 24
Location: my pc

PostPosted: Wed Feb 18, 2009 2:15 pm
Reply with quote

I guess you require the O/P in a flat file. If yes, then unload the table to a dataset and use ICETOOL/DFSORT.

refer to the link below

www.ibmmainframes.com/about28396.html
Back to top
View user's profile Send private message
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Wed Feb 18, 2009 2:21 pm
Reply with quote

Could you please expalin your problem. Do you want the ouput in the flat file or Row column is one of the columns in Table?
Back to top
View user's profile Send private message
VIGNRSH
Warnings : 1

New User


Joined: 18 Mar 2007
Posts: 44
Location: New Jersey,USA

PostPosted: Tue Feb 24, 2009 6:51 pm
Reply with quote

I want it as a column in the output, not inf the flat file.
The bsiness requirement is that ,
the column generated with the above seq numbers based on the key,
to be merged with other table in the join condition.
My seniors have asked me, to do only this part, and iam not sure of the other or actual requirement.

We are in db2 version 8.
So we cannotconsider using the row_number () function !
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Feb 24, 2009 10:39 pm
Reply with quote

Hello,

Quote:
I want it as a column in the output, not inf the flat file.
?
Quote:
to be merged with other table in the join condition.
What other table? I am probably mis-reading something, but i see only one table. I'm not sure where JOIN can be used for this.

Is this ROW column to be part of the/a key? Is the ROW column already defined in the table?

One easy way to generate the ROW value would be to be a programmer for a few minutes, declare a cursor ordering by COL1 COL2, fetch each row and generate the proper ROW value depending if a new 1 was needed or an increment to the existing value was needed.
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 Adding QMF and SPUFI to the ISPF menu DB2 20
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts Adding first / last acct numerber to ... DFSORT/ICETOOL 7
No new posts Adding 'ODD' and 'EVEN' indicator at ... DFSORT/ICETOOL 6
No new posts To search DB2 table based on Conditio... DB2 1
Search our Forums:

Back to Top