CREATE TABLE test (a VARCHAR(2000))
INSERT INTO test
VALUES ('This is a AB_CD_test.dbo.ABC'),
('This is a AB_CD.dbo.ABC')
Table before running Update query:
This is a AB_CD_test.dbo.ABC
This is a AB_CD.dbo.ABC
This is a [AB_CD].[dbo].[XYZ]
I am trying to replace the keyword AB_CD with AB_CD_test using this query:
UPDATE [US\AF83767].[test]
SET a = REPLACE(a, 'AB_CD', 'AB_CD_test')
WHERE a LIKE '%AB!_CD%' ESCAPE '!';
But as expected, data changes to:
This is a AB_CD_test_test.dbo.ABC
This is a AB_CD_test.dbo.ABC
This is a [AB_CD_test].[dbo].[XYZ]
The second is fine but the first should remain 'This is a AB_CD_test.dbo.ABC'.
Could anyone help with a query which does not change the first row and just looks for occurrences of 'AB_CD'.
Relatively new to SQL and would appreciate your help.