SQL Server:如何删除所有记录中的特定列的数据

时间:2021-06-08 07:54:54

I have a table like this

我有一张这样的桌子

Id  | Action
----+---------------------------------
 1  | GetUser
 2  | Restriction/GetRestrictedUsers

I would like to delete all expressions including '/' slash symbol in all records

我想在所有记录中删除所有表达式,包括'/'斜杠符号

For instance Restriction/GetRestrictedUsers this should be like this GetRestrictedUsers

例如Restriction / GetRestrictedUsers这应该像这个GetRestrictedUsers

Any help?

3 个解决方案

#1


1  

Hmmm . . . Try this (after making a backup of the table):

嗯。 。 。试试这个(在备份表之后):

update t
    set action = substring(action, charindex('/', action) + 1, len(action))
    where action like '%/%';

#2


2  

update table_name
set Action = SUBSTRING(Action, Charindex('/', action) + 1,len(action))
where action like '%/%';

#3


0  

As an alternative, the PARSENAME function (2012+) could be abused for this.

作为替代方案,PARSENAME功能(2012+)可能会被滥用。

update [YourTable]
set Action = PARSENAME(REPLACE(Action,'/','.'), 1)
where action like '%/%[^/]';

#1


1  

Hmmm . . . Try this (after making a backup of the table):

嗯。 。 。试试这个(在备份表之后):

update t
    set action = substring(action, charindex('/', action) + 1, len(action))
    where action like '%/%';

#2


2  

update table_name
set Action = SUBSTRING(Action, Charindex('/', action) + 1,len(action))
where action like '%/%';

#3


0  

As an alternative, the PARSENAME function (2012+) could be abused for this.

作为替代方案,PARSENAME功能(2012+)可能会被滥用。

update [YourTable]
set Action = PARSENAME(REPLACE(Action,'/','.'), 1)
where action like '%/%[^/]';