如何根据匹配的特殊字符更新 sql 列



我正在尝试删除数据库中的一些坏字符。我目前正在处理的行以项目符号和空格开头。但是,我的 where 子句与有问题的行不匹配。如何获得匹配?这就是我目前正在尝试的。

update Skill
set Name = substring(Name, 3, 50)
where Name like char(150) + ' %'

也许您没有捕获正确的 ASCII 值。这是使用类似方法的 unicode 方法。

declare @table table ([Name] nvarchar(64))
insert into @table
values
('- some data')
select 
    UNICODE(left([Name],1))        --this will tell you what VALUE to use in the where clause
    ,NCHAR(UNICODE(left([Name],1)))
from @table
update @table
set [Name] = substring([Name], 3, 50)
where UNICODE(left([Name],1)) = 45 --use the appropriate UNICODE values here

select * from @table

如注释中所述,您可以使用 ASCII() 获取您要查找的字符的代码,然后在更新中使用该代码。

UPDATE Skill
set Name = substring(Name, 3, 50)
WHERE LEFT(name,1) = CHAR(149)

最新更新