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 

column of generated sequence numbers ?

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


Joined: 10 Feb 2006
Posts: 188
Topics: 68

PostPosted: Tue Nov 01, 2011 1:27 pm    Post subject: column of generated sequence numbers ? Reply with quote

Is there a way to insert a column of sequence numbers in QMF, so that each row returned will have a number associated with it?

Code:
                               New Seq # column:
FIELDA    FIELDB   FIELDC      000001
FIELDA    FIELDB   FIELDC      000002


Thanks for any help.
Back to top
View user's profile Send private message
Sqlcode
Intermediate


Joined: 15 Dec 2006
Posts: 157
Topics: 38

PostPosted: Tue Nov 01, 2011 1:34 pm    Post subject: Reply with quote

tcurrier,
See if below helps... DB2 V9

If you need leading zeros, you need to cast sequence number for char and use digits.
Code:
SELECT FIELDA,FIELDB,ROW_NUMBER () OVER () AS SEQ_NUM
FROM TABLE


Thanks,
Back to top
View user's profile Send private message
tcurrier
Intermediate


Joined: 10 Feb 2006
Posts: 188
Topics: 68

PostPosted: Tue Nov 01, 2011 5:06 pm    Post subject: Reply with quote

I only have version 8. Any chance of getting this functionality in V8 ?
Back to top
View user's profile Send private message
GuyC
Supermod


Joined: 27 May 2011
Posts: 35
Topics: 0

PostPosted: Wed Nov 02, 2011 5:44 am    Post subject: Reply with quote

only a not so performant one :
Code:
SELECT FIELDA,FIELDB
,(select 1+count(*) from table1 B where B.uniquesortkey < A.uniquesortkey)
FROM TABLE1 A
order by uniquesortkey

at least I think you can select in the column list in v8
otherwise :

Code:
SELECT FIELDA,FIELDB
,seq
FROM TABLE1 A
join table (select 1+count(*) as seq from table1 B where B.uniquesortkey < A.uniquesortkey) C on 1=1
order by uniquesortkey
Back to top
View user's profile Send private message
tcurrier
Intermediate


Joined: 10 Feb 2006
Posts: 188
Topics: 68

PostPosted: Wed Nov 02, 2011 8:59 am    Post subject: Reply with quote

I got the following error using the second query :

Code:
SELECT POL_NUM, POL_SUFFIX                                   
,SEQ                                                         
FROM H2591DB.TCSAU_GENI A                                     
JOIN TABLE (SELECT 1+COUNT(*)                                 
AS SEQ FROM H2591DB.TCSAU_GENI B                             
WHERE B.UNIQUESORTKEY < A.UNIQUESORTKEY) C ON 1=1             
ORDER BY UNIQUESORTKEY       
                                 
QUERY MESSAGES:                                               
Column B.UNIQUESORTKEY is not in any table named in the query.
*** END ***                                                   
Back to top
View user's profile Send private message
GuyC
Supermod


Joined: 27 May 2011
Posts: 35
Topics: 0

PostPosted: Wed Nov 02, 2011 12:11 pm    Post subject: Reply with quote

no comment, just this :
Code:
SELECT POL_NUM, POL_SUFFIX                                   
,SEQ                                                         
FROM H2591DB.TCSAU_GENI A                                     
JOIN TABLE (SELECT 1+COUNT(*)                                 
AS SEQ FROM H2591DB.TCSAU_GENI B                             
WHERE B.POL_NUM< A.POL_NUM) C ON 1=1             
ORDER BY POL_NUM
Back to top
View user's profile Send private message
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