我有一张表,有个字段是主键,字符型的,
以前在输记录的时候,输了些标点,现在想把这些标点去掉,
例如;0001?我现在想改成0001 不知道怎么改,高手指教下 

解决方案 »

  1.   

    update tablea
    set col = replace(col,'?','')
      

  2.   

    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
      

  3.   


    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)