The above UPDATE statement looks reasonable enough. Be aware that using this on fixed-length columns that can have trailing blanks might require the use of %TRIM() to locate the last significant character.
Tom
Carlos,
I'm not certain that the AS/400 SQL has CHAR_LENGTH
this will remove trailing 'M'
UPDATE mbmtest01/itemaster
SET ITNBR = CONCAT(substring(ITNBR,1, LENGTH(trim(ITNBR))-1),’ ‘)
WHERE substring(ITNBR, LENGTH(trim(ITNBR)),1) = ‘M’
but will, I fear, fail if the field is blank.
Phil
When I try this code:
UPDATE mbmtest01/itemaster
SET ITNBR = CONCAT(LEFT(ITNBR,CHAR_LENGTH(ITNBR)-1),’ ‘)
WHERE right(ITNBR,1) = ‘M’
I get an: Duplicate key value specified. error How could that be happening
Thanks to all
I’m not certain that the AS/400 SQL has CHAR_LENGTH...
The CHARACTER_LENGTH() (and CHAR_LENGTH()) function has been in DB2 for a long time. Not used much, since LENGTH() is shorter.
Tom
Hmmm.
There is no way you can insert duplicate values or create them with an update on a column with a unique index.
If the column has a unique index on it, it means that no duplicates should exist for that column, so, you should not try to create duplicates. If duplicates are going to be allowed, then you should drop the unique index.
You might want to review the results you would get with this update (what rows are going to be affected ? how are they going to be affected ?), and make sure this is the correct way to achive your objectives.
You're right the key is unique and as I reviewed the data there is a few fields that removing the trailing character 'M' would cause them to become duplicates. No secondary key so this would cause other problems if allowed to proceed. Thanks you are so very right! This IS great stuff.
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 11  Replies