create table tb( pk_id varchar(100) primary key)insert tb select '001?' union all select '002' union all select '003?'update tb set pk_id=left(pk_id,len(pk_id)-1) where right(pk_id,1)='?'select * from tbdrop table tb
1、如果字符串里面的符号不多,就那几个的话 可以用楼上的方法进行替换:update tablename set id=replace(replace(id,',',''),'?','')2、如果数据太多,符号也太多,楼主嫌麻烦。可以用函数修改。 create function wsp(@s varchar(1000)) returns varchar(1000) as begin while(patindex('%[^0-9]%',@s)>0) begin set @s=substring(@s,1,patindex('%[^0-9]%',@s)-1)+ substring(@s,patindex('%[^0-9]%',@s)+1,len(@s)) end return @s endupdate tablename set id=dbo.wsp(id)
set col = replace(col,'?','')
pk_id varchar(100) primary key)insert tb select '001?'
union all select '002'
union all select '003?'update tb set pk_id=left(pk_id,len(pk_id)-1) where right(pk_id,1)='?'select * from tbdrop table tb
1、如果字符串里面的符号不多,就那几个的话
可以用楼上的方法进行替换:update tablename set id=replace(replace(id,',',''),'?','')2、如果数据太多,符号也太多,楼主嫌麻烦。可以用函数修改。
create function wsp(@s varchar(1000))
returns varchar(1000)
as
begin
while(patindex('%[^0-9]%',@s)>0)
begin
set @s=substring(@s,1,patindex('%[^0-9]%',@s)-1)+
substring(@s,patindex('%[^0-9]%',@s)+1,len(@s))
end
return @s
endupdate tablename set id=dbo.wsp(id)