I want to match an exact word and replace it with another word.
Here is the SQL Server query that I am using:
UPDATE BODYCONTENT
SET BODY = CAST(REPLACE(CAST(BODY AS NVARCHAR(MAX)), 'Test' , 'prod') AS NTEXT)
WHERE BODY COLLATE Latin1_General_CI_AS LIKE '%Test%' COLLATE Latin1_General_CI_AS;
What this query is doing:
'Test','test','TEST' is updated into 'prod' -- This is expected.
'Test2','TestTest', 'Fastest' is updated into 'prod' - I want to avoid this behavior.
Please help.
Other queries I tried but didn't work:
UPDATE BODYCONTENT
SET BODY = CAST(REPLACE(CAST(BODY AS NVARCHAR(MAX)), 'Test' , 'prod') AS NTEXT)
WHERE BODY COLLATE Latin1_General_CI_AS LIKE '%[^A-Za-z0-9]Test[^A-Za-z0-9]%' COLLATE Latin1_General_CI_AS;
And when I do a select for 'Test' using the below query:
SELECT *
FROM dbo.BODYCONTENT
WHERE CONVERT(NVARCHAR(MAX), BODY) = N'Test';
It is not returning anything. But I could get results using the below queries:
SELECT BODY
FROM dbo.BODYCONTENT
WHERE BODY LIKE '%Test%';
SELECT BODY
FROM dbo.BODYCONTENT
WHERE BODY COLLATE Latin1_General_CI_AS like '%TEST%' COLLATE Latin1_General_CI_AS;
Here is the column value:
Test testtest Test1 Test TEST
Expected result:
prod testtest Test1 prod prod
Current result:
prod prodprod prod1 prod prod