sql替换字符

declare @name varchar(100)='"acct_name"',@card varchar(100)='"id_no"'

SELECT TOP 100   
    stuff(

   STUFF(Json, 
        CHARINDEX(@name, Json) + LEN(@name) + 2, 
        CHARINDEX(',',Json,CHARINDEX(@name, Json) + LEN(@name)) - CHARINDEX(@name, Json) - LEN(@name) - 3, 
        replicate('*',CHARINDEX(',',Json,CHARINDEX(@name, Json) + LEN(@name)) - CHARINDEX(@name, Json) - LEN(@name) - 3)
        ),

        CHARINDEX(@card, Json) + LEN(@card) + 6,
        CHARINDEX(',',Json,CHARINDEX(@card, Json) + LEN(@name)) - CHARINDEX(@card, Json) - LEN(@card) - 11,
        replicate('*',CHARINDEX(',',Json,CHARINDEX(@card, Json) + LEN(@name)) - CHARINDEX(@card, Json) - LEN(@card) - 11)

        ),

     CHARINDEX(@name, Json) + LEN(@name) + 2,
     CHARINDEX(',',Json,CHARINDEX(@name, Json) + LEN(@name)) - CHARINDEX(@name, Json) - LEN(@name) - 3,  
     CHARINDEX(@card, Json) + LEN(@card) + 6,
     CHARINDEX(',',Json,CHARINDEX(@card, Json) + LEN(@name)) - CHARINDEX(@card, Json) - LEN(@card) - 11,

     --SUBSTRING(Json, 0, CHARINDEX(@name, Json) + LEN(@name) + 2) + 
     --REPLICATE('*', CHARINDEX(',',Json,CHARINDEX(@name, Json) + LEN(@name)) - CHARINDEX(@name, Json) - LEN(@name) - 3)  

     --stuff
     Json 
     FROM dbo.Z_UserBankInfo WHERE json IS NOT null

 

posted @ 2016-02-23 18:09  一千零一夜  阅读(746)  评论(0编辑  收藏  举报