查找并替换列中的特定字符串

时间:2021-08-01 18:07:47

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.

域主要是本地计算机名称(用户存在于系统中)。我正在尝试编写一个简单的SQL查询来查找模式(计算机名称)并替换为新模式。

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

我不太熟悉SQL查询。你能分享一个样本片段吗?我正在使用SQL Server 2008

2 个解决方案

#1


9  

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

is that?

就是它?

#2


0  

Try this statement:

试试这句话:

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

#1


9  

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

is that?

就是它?

#2


0  

Try this statement:

试试这句话:

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