How to Do a Simple 'Find and Replace" in Mssql

How do I do a simple 'Find and Replace in MsSQL?

The following query replace each and every a character with a b character.

UPDATE 
YourTable
SET
Column1 = REPLACE(Column1,'a','b')
WHERE
Column1 LIKE '%a%'

This will not work on SQL server 2003.

SQL Server simple find/replace on text string within a table column

Seems to work fine for me:

http://sqlfiddle.com/#!3/451de/1

My guess is that the owner of My_Table isn't dbo? Can you:

SELECT * FROM dbo.My_Table

Good luck.

SQL Server find and replace specific word in all rows of specific column

UPDATE tblKit
SET number = REPLACE(number, 'KIT', 'CH')
WHERE number like 'KIT%'
  • SQLFiddle Demo

or simply this if you are sure that you have no values like this CKIT002

UPDATE tblKit
SET number = REPLACE(number, 'KIT', 'CH')
  • SQLFiddle Demo

SQL replace - find word and replace it

you need the text column in replace

Update TABLE
SET Text = replace(text, 'TEAM', 'AMOUNT')
Where text like '%TEAM%'

seems you are not using mysql but sql.serve and you have ntext

so you could try using a cast

Update TABLE
SET Text = replace(cast text as nvarchar(4000), 'TEAM', 'AMOUNT')
Where text like '%TEAM%'

SQL query for FIND and REPLACE with if condition

Assuming you are looking for this

UPDATE post_meta
SET post_value = REPLACE(post_value, '/folder/', '/events/')
WHERE parent_post = 342

How to replace a string in a SQL Server Table Column

It's this easy:

update my_table
set path = replace(path, 'oldstring', 'newstring')

Quickest/Easiest way to use Search/Replace through all stored procedures

To search: if you need to find database objects (e.g. tables, columns, triggers) by name - have a look at the FREE Red-Gate tool called SQL Search which does this - it searches your entire database for any kind of string(s).

Sample Image

Sample Image

It's a great must-have tool for any DBA or database developer - did I already mention it's absolutely FREE to use for any kind of use?

This tool doesn't support replacing text, however - but even just being able to find all the relevant stored procedures (or other DB objects) is very helpful indeed!



Related Topics



Leave a reply



Submit