Update substring of a column

前端 未结 3 1651
猫巷女王i
猫巷女王i 2021-01-01 17:03

I have a table within a SQL Server 2008 database called Meter. This table has a column called Name.

Each entry within the column Nam

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 17:54

    UPDATE Meter
    SET Name = 'ZAA_' + SUBSTRING(Name, 4, LEN(Name))
    WHERE SUBSTRING(Name, 1, 4) = 'ZAA\'
    

    Edit:

    Or as @Damien_The_Unbliever states, to use an index:

    UPDATE Meter
    SET Name = 'ZAA_' + SUBSTRING(Name, 4, LEN(Name))
    WHERE Name LIKE 'ZAA\%'
    

    EDIT

    From your comment, try this statement to fix the additional \:

    UPDATE Meter
    SET Name = 'ZAA_' + SUBSTRING(Name, 5, LEN(Name))
    WHERE Name LIKE 'ZAA_\%'
    

提交回复
热议问题