代码之家  ›  专栏  ›  技术社区  ›  So_oP

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

  •  -3
  • So_oP  · 技术社区  · 7 年前

    我有一张这样的桌子

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

    我想删除所有表达式,包括 “/” 所有记录中的斜线符号

    例如 Restriction/GetRestrictedUsers 这个应该是这样的 GetRestrictedUsers

    有什么帮助吗?

    3 回复  |  直到 7 年前
        1
  •  1
  •   Gordon Linoff    7 年前

    六羟甲基三聚氰胺六甲醚。…尝试此操作(备份表后):

    update t
        set action = substring(action, charindex('/', action) + 1, len(action))
        where action like '%/%';
    
        2
  •  2
  •   Tanveer Singh Bhatia    7 年前
    update table_name
    set Action = SUBSTRING(Action, Charindex('/', action) + 1,len(action))
    where action like '%/%';
    
        3
  •  0
  •   LukStorms    7 年前

    作为替代方案, PARSENAME 函数(2012+)可能因此被滥用。

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