1

嗨,我想从我正在尝试使用存储过程的表中删除特殊字符,你们中的任何人都可以提出更好的方法吗?我只想删除某些特殊字符,例如?, ', ",#并且我的日期仍然有$或其他一些符号。

     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
4

1 回答 1

1

尝试这样的事情: -

SELECT REPLACE( REPLACE( REPLACE( REPLACE( @str, '!', '' ), '#', '' ), '$', '' ), '&', '' );
于 2013-09-26T18:32:24.170 回答