您好我想从我的表中删除特殊字符我尝试使用存储过程
你们中的任何人都可以建议一种更好的方法。我只想删除某些特殊字符,例如?
,'
,"
,#
,而我的日期仍有$
或其他符号。
CREATE PROCEDURE [dbo].[ScrubData]
(
@TableName Varchar(100)
)
AS
BEGIN
DECLARE @SQL1 nVARCHAR(MAX)
DECLARE @SQL2 nVARCHAR(MAX)
DECLARE @SQL3 nVARCHAR(MAX)
DECLARE @SQL4 nVARCHAR(MAX)
select @SQL1 =
'update ' + TABLE_NAME +
' set ' + column_name + ' = replace ('+ column_name +', '','','''')
where ' + column_name + ' like ''%,%'''
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = @TableName and COLUMN_NAME like '%load'
select @sql2 =
'update ' + TABLE_NAME +
' set ' + column_name + ' = replace ('+ column_name +', '''''','''')
where ' + column_name + ' like ''%''%'''
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = @TableName and COLUMN_NAME like '%load'
select @SQL3 =
'update ' + TABLE_NAME +
' set ' + column_name + ' = replace ('+ column_name +', ''"'','''')
where ' + column_name + ' like ''%"%'''
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = @TableName and COLUMN_NAME like '%load'
select @SQL4 =
'update ' + TABLE_NAME +
' set ' + column_name + ' = replace ('+ column_name +', ''#'','''')
where ' + column_name + ' like ''%#%'''
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = @TableName and COLUMN_NAME like '%load'
print(@sql1)
print(@sql2)
print(@sql3)
print(@sql4)
end
答案 0 :(得分:1)
尝试这样的事情: -
SELECT REPLACE( REPLACE( REPLACE( REPLACE( @str, '!', '' ), '#', '' ), '$', '' ), '&', '' );