MSSQL 回车字符导致数据替换处理

/*数据库中出回车字符导致PDA同步错误*/
select * from SHANGPIN where SPDM='163190A992'

select CONCAT('%', char(13),'%')
select CONCAT( '%',char(13),'%')  -- 巧克力熊 美容套装
--1.查询出回车的数据
declare @shift as varchar(5)
set @shift =  CONCAT( '%',char(13),'%')
--2.下图为回车字符类型,注意直接用回车
--select replace('HelloWorld!','o','e') 结果为:HelleWerld!

select SPDM,REPLACE(SPMC,'
','') AS SPMCOK,SPMC INTO #isSHANGPIN_temp20160511
from SHANGPIN 
where SPMC like '%
%'  and 
SPDM in('163190A992','163190A993','163190A994','163190A991','163190A995','163190A996',
'163190A997','163190A998','161190A611')

select * from #isSHANGPIN_temp20160511

--3.修复更新错误数据
--select B.SPMCOK,* from 
update A set A.SPMC=B.SPMCOK FROM
SHANGPIN A inner join #isSHANGPIN_temp20160511 B
on A.SPDM=B.SPDM 
AND A.SPDM in('163190A992','163190A993','163190A994','163190A991','163190A995','163190A996',
'163190A997','163190A998','161190A611')
--4.确认数据
 SELECT * FROM
SHANGPIN A where A.SPDM in('163190A992','163190A993','163190A994','163190A991','163190A995','163190A996',
'163190A997','163190A998','161190A611')

你可能感兴趣的:(MSSQL 回车字符导致数据替换处理)