SQL Server: How do you remove punctuation from a field?

前端 未结 8 1388
甜味超标
甜味超标 2021-02-05 20:50

Any one know a good way to remove punctuation from a field in SQL Server?

I\'m thinking

UPDATE tblMyTable SET FieldName = REPLACE(REPLACE(REPLACE(FieldNa         


        
8条回答
  •  半阙折子戏
    2021-02-05 21:17

    I wanted to avoid creating a table and wanted to remove everything except letters and digits.

    DECLARE @p int
    DECLARE @Result Varchar(250)
    DECLARE @BadChars Varchar(12)
    SELECT @BadChars = '%[^a-z0-9]%'
    -- to leave spaces - SELECT @BadChars = '%[^a-z0-9] %'
    
    SET @Result = @InStr
    
    SET @P =PatIndex(@BadChars,@Result)
    WHILE @p > 0 BEGIN
        SELECT @Result = Left(@Result,@p-1) + Substring(@Result,@p+1,250)
        SET @P =PatIndex(@BadChars,@Result)
        END
    

提交回复
热议问题