sarat
sarat

Reputation: 11160

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

Upvotes: 4

Views: 6146

Answers (2)

Toshim Shaikh
Toshim Shaikh

Reputation: 1

Try this statement:

UPDATE your_table SET machine_name = REPLACE(machine_name, machine_name, 'Your New Value')

Upvotes: 0

dani herrera
dani herrera

Reputation: 51715

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

is that?

Upvotes: 9

Related Questions