Using AS/400 SQL to replace a variable string

41430 pts.
Tags:
AS/400
AS/400 SQL
SQL
I need to do a scan and replace in a flat file. File has one field 80 characters long. Possibly one or more of the records in the file contain a specific value, such as '%ABC%' and I want to update the record replace ABC with XYZ. This value could be anywhere within the record. I do not want to take the time to do an RPG program. Prefer to use RUNSQLSTM. Any ideas?

Software/Hardware used:
AS400 V5R4

Answer Wiki

Thanks. We'll let you know when a new response is added.

In v6r1 and maybe before you can use REPLACE function
update Myfile set MyField = replace(Myfield,’ABC’,’XYZ’)

but use care – this will replace every ABC with XYZ
even the second or third occurance on the same record.

I recommend that you view the data first

Select Myfield from MyFile
where MyField like ('%ABC%')

Phil

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • CharlieBrowne
    Thanks Phil Worked perfert. I had tried REPLACE but had the wrong syntax.
    41,430 pointsBadges:
    report
  • JerryHandler
    how about v5r2? can i do it?
    10 pointsBadges:
    report
  • Sloopy
    You can do it in V5R4.
    2,195 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following