Are you on V5R4? If so, then something like this ought to work:

INSERT INTO toFile
(SELECT order#,
ROW_NUMBER () OVER(PARTITION BY order# ORDER BY order#)
FROM fromFile)

Elvis

Celebrating 11-Years of SQL Performance Excellence on IBM i, i5/OS and
OS/400
www.centerfieldtechnology.com

-----Original Message-----
Subject: SQL Insert with an incrementing line number

Hey all, can this be done with sql?

insert from one file into another -

"from" file has duplicates for order#, no line.
"to" file keyed by order# / line

I want to auto generate the line number in the "to" file, incrementing
by one for each group of orders, resetting on a change in order
numbers.

I looked at NEXT VALUE using sequence objects, but that doesn't seem
to allow the reset on order number breaks.

Thanks in advance,

Rick



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.