Link to home
Start Free TrialLog in
Avatar of Remisglez
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.
Avatar of kretzschmar
kretzschmar
Flag of Germany image

for what database?
Avatar of Remisglez
Remisglez

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
ASKER CERTIFIED SOLUTION
Avatar of Mike Littlewood
Mike Littlewood
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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