Oops, small correction on a file name in the correlated subquery:
UPDATE myFile a SET a.suffix =
CASE flag WHEN 'Y' THEN '00'
ELSE
(SELECT b.suffix
FROM (SELECT master, contract,
RIGHT(DIGITS(ROW_NUMBER()
OVER(PARTITION BY master
ORDER BY contract)),2)
AS suffix
FROM myFile
WHERE flag = 'N') b
WHERE a.master = b.master AND a.contract = b.contract)
END
Celebrating 11-Years of SQL Performance Excellence on IBM i5/OS and OS/400
www.centerfieldtechnology.com
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Elvis Budimlic
Sent: Wednesday, April 23, 2008 1:20 PM
To: 'Midrange Systems Technical Discussion'
Subject: RE: Sql - updating multiple records with a sequential value
Mike, based on further fleshing out of your requirements, I believe this
ought to work:
UPDATE myFile a SET a.suffix =
CASE flag WHEN 'Y' THEN '00'
ELSE
(SELECT b.suffix
FROM (SELECT master, contract,
RIGHT(DIGITS(ROW_NUMBER()
OVER(PARTITION BY master
ORDER BY contract)),2)
AS suffix
FROM qtemp/t1
WHERE flag = 'N') b
WHERE a.master = b.master AND a.contract = b.contract)
END
Elvis
Celebrating 11-Years of SQL Performance Excellence on IBM i5/OS and OS/400
www.centerfieldtechnology.com
-----Original Message-----
Subject: Sql - updating multiple records with a sequential value
I am adding some new fields to a file. The file containts a master
contract#, contract# and (new) contract suffix
MASTER CONTRACT MASTER Flag SUFFIX
200300022 Y 00
200300022 200500120 N
200300022 200500121 N
200300022 200600124 N
I want to be able to update the suffix with 01, 02, 03, etc for each
master contract that matches a contract
So if mastflg = 'y', update suffix(incrementing value) where contract =
master
Can I do this with SQL? I'm not sure how to make the suffix field
increment.
Thanks
Mike
As an Amazon Associate we earn from qualifying purchases.
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.