Remisglez
asked on
I need replace a part of a string in a whole field at the same time
Hello experts, I need to make a query for replacing a part of a string in a database, for example
Cuenta
--------
123456
125469
277456
I need to replace 456 for XXX (is a string)
¿how can I make this query in delphi?
Thanks.
Cuenta
--------
123456
125469
277456
I need to replace 456 for XXX (is a string)
¿how can I make this query in delphi?
Thanks.
for what database?
ASKER
Hi kretzschmar, the database is Foxpro IV (.dbf)
Ok Im assuming that you have an index on the table which is a number, if so this will do it
UPDATE <Table>
SET <STRINGFIELD> = SubString(<STRINGFIELD>,1, 3) + 'XXX'
WHERE <INDEXFIELD> IN
(
SELECT <INDEXFIELD> FROM <Table>
WHERE SubString(<STRINGFIELD>,4, 3) = '456'
)
just replace the obvious bits with your table etc
UPDATE <Table>
SET <STRINGFIELD> = SubString(<STRINGFIELD>,1,
WHERE <INDEXFIELD> IN
(
SELECT <INDEXFIELD> FROM <Table>
WHERE SubString(<STRINGFIELD>,4,
)
just replace the obvious bits with your table etc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or
use YourTable
replace all YourField with substr(YourField, 1, at("456", YourField)-1)+"XXX"+substr (YourField , at("456", YourField)+3, 50) for at("456", YourField) > 0
use YourTable
replace all YourField with substr(YourField, 1, at("456", YourField)-1)+"XXX"+substr