Update substring of a column

前端 未结 3 1628
猫巷女王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条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-01 18:00

    Here is the SQLFiddel Demo

    Below is the Query which you can try

    CREATE TABLE Meter
        ([Name] varchar(7))
    ;
    
    INSERT INTO Meter
        ([Name])
    VALUES
        ('ZAA\001')
    ;
    
    
    select * from Meter;
    
    Update Meter
       set Name = stuff(Name,4,1,'_')
     Where SUBSTRING(Name, 1,4) ='ZAA' + Char(92);
    
    select * from Meter;
    

提交回复
热议问题