sqlServer中Replace函数的运用
replace(‘表中的字段’,‘要替换的字符’,‘替换后的新字符’)
--建测试表:
Create table #testTab
(
id int identity(1,1) primary key,
NumberStr1 varchar(50) not null,
NumberStr2 varchar(50) not null,
)
--增加测试数据
insert into #testTab values('123456','张B晨')
insert into #testTab values('123456','B福剑')
--运用(将NumberStr1字段中包含123的值全部替换成一二三,将NumberStr2 字段中为B的替换成碧)
SELECT NumberStr1=(REPLACE(NumberStr1,'123','一二三')),NumberStr2=(REPLACE(NumberStr2,'B','碧')) FROM #testTab;
演示效果展示: