Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find and replace particular string in a column

I have a table in the database where it contains some of the user name. When I copy the database files from one machine to other machine, I need to manually update this table. The table contains the username in the following format

<domain name>\Username

the domain mostly the local machine name (the user exists within the system). What I am trying to write a simple SQL Query to find a pattern (machine name) and replace with a new one.

I am not so proficient with SQL queries. Can you share a sample snippet? I am using SQL Server 2008

like image 258
sarat Avatar asked Jan 18 '23 08:01

sarat


1 Answers

UPDATE table_that_contains_users
SET field_user = replace( field_user, 'OLDDOMAIN\', 'NEWDOMAIN\')

is that?

like image 142
dani herrera Avatar answered Jan 27 '23 06:01

dani herrera