异常处理汇总-数据库系列 http://www.cnblogs.com/dunitian/p/4522990.html
先看看啥情况
复制查询到的数据,粘贴一下看看啥情况
那就批量处理一下~
就这样?NONONO,衍伸一下~我们的各种偷懒(世界就是懒人改变的)
先简单封装
--初步封装
declare @cloumnName varchar(100)=‘TName‘
update ShopMenuType set @cloumnName=replace(@cloumnName,char(10),‘‘) --- 除去换行符
update ShopMenuType set @cloumnName=replace(@cloumnName,char(13),‘‘) --- 除去回车符
update ShopMenuType set @cloumnName=replace(@cloumnName,‘ ‘,‘‘) --- 除去空格符
尝试尝试是否可以深度封装
最终封装(还可再简,如有更好方法欢迎贴出,逆天感激不尽)
declare @tableName varchar(100),@cloumnName varchar(100),@sqlStr nvarchar(1000)
select @tableName=‘ShopMenuType‘,@cloumnName=‘TName‘--每次替换这里的表名和列名就可以了
set @sqlStr=‘update ‘[email protected]+‘ set ‘[email protected]+‘=replace(‘[email protected]+‘,char(10),‘‘‘‘)‘ --- 除去换行符
set @[email protected]+‘ update ‘[email protected]+‘ set ‘[email protected]+‘=replace(‘[email protected]+‘,char(13),‘‘‘‘)‘ --- 除去回车符
set @[email protected]+‘ update ‘[email protected]+‘ set ‘[email protected]+‘=replace(‘[email protected]+‘,‘‘ ‘‘,‘‘‘‘)‘ --- 除去空格符
print @sqlStr
exec(@sqlStr)