我想写一段数据库代码实现如下功能,请各位大虾帮写一下呀。
实现功能:替换字符串(身份证)中的X为*,因为数据很多有十万记录,ID从1到190020。所以想写一段代码实现一次性专换。表的大体结构是:id(int)
                    identyid(身份证) nvarchar(18)
其他字段先不写了,只专换身份证的这个字段就行了
谢谢各位大虾指教

解决方案 »

  1.   

    update tablename set identyid=replace(identyid,'x','*')
      

  2.   

    --tryupdate tablename
    set identyid=left(identyid,17)+'*'
    where right(identyid,1)='*'
      

  3.   

    update tablename
    set identyid=left(identyid,17)+'*'
    where right(identyid,1)='X'
      

  4.   

    Update T1
    Set IdentityID=Replace(IdentityID,N'X',N'*')
    Where Id Between 1 And 190020
      

  5.   

    仅最后一个验证码有可能是X顺便附上函数一个(15转18)SET QUOTED_IDENTIFIER ON 
    GO
    SET ANSI_NULLS ON 
    GOcreate  Function dbo.F_IdCard15to18(@sCode15 varchar(15))
    returns varchar(18)
    as
    begin
    declare @IDCode15to18 as varchar(18) --输出的18位二代身份证号
    declare @i as int
    declare @num as int
    --declare @code as varchar(10)
    set @num=0
    set @IDCode15to18=Left(@sCode15,6)+'19'+Right(@sCode15, 9)--计算校验位
    set @i=18
    while @i>=1
    begin
    select @num=@num+(power(2,(@i-1))%11)*cast(substring(@IDCode15to18,19-@i,1) as int)
    select @i=@i-1
    end
    select @num=@num%11
    select @IDCode15to18=@IDCode15to18+case @num
    when 0 then '1'
    when 1 then '0'
    when 2 then 'X'
    else rtrim(12-@num) end
    return @IDCode15to18
    endGO
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO