Using AS400 SQL to replace a variable string
6540 pts.
0
Q:
Using AS400 SQL to replace a variable string
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
ASKED: Sep 30 2009  7:01 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
24540 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
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
Last Answered: Sep 30 2009  8:52 PM GMT by Philpl1jb   24540 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

CharlieBrowne   6540 pts.  |   Oct 1 2009  12:53PM GMT

Thanks Phil
Worked perfert.
I had tried REPLACE but had the wrong syntax.

 

JerryHandler   10 pts.  |   Oct 27 2009  11:34AM GMT

how about v5r2? can i do it?

 

Sloopy   1940 pts.  |   Oct 28 2009  4:10PM GMT

You can do it in V5R4.

 
0