Find and replace a specific row in a column

I have a table in the database that contains some username. When I copy database files from one computer to another computer, I need to manually update this table. The table contains the username in the following format

<domain name>\Username 

the domain is basically the name of the local machine (the user exists on the system). I am trying to write a simple SQL query to find a pattern (machine name) and replace it with a new one.

I do not understand SQL queries. Can you share a sample fragment? I am using SQL Server 2008

+4
source share
2 answers
 UPDATE table_that_contains_users SET field_user = replace( field_user, 'OLDDOMAIN\', 'NEWDOMAIN\') 

- this is?

+9
source

Try the following statement:

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

Source: https://habr.com/ru/post/1380370/


All Articles