Regex pattern inside SQL Replace function?

前端 未结 10 1402
梦谈多话
梦谈多话 2020-11-22 12:42
SELECT REPLACE(\'100.00 GB\', \'%^(^-?\\d*\\.{0,1}\\d+$)%\', \'\');

I want to replace any markup between two

10条回答
  •  时光取名叫无心
    2020-11-22 12:55

    Instead of stripping out the found character by its sole position, using Replace(Column, BadFoundCharacter, '') could be substantially faster. Additionally, instead of just replacing the one bad character found next in each column, this replaces all those found.

    WHILE 1 = 1 BEGIN
        UPDATE dbo.YourTable
        SET Column = Replace(Column, Substring(Column, PatIndex('%[^0-9.-]%', Column), 1), '')
        WHERE Column LIKE '%[^0-9.-]%'
        If @@RowCount = 0 BREAK;
    END;
    

    I am convinced this will work better than the accepted answer, if only because it does fewer operations. There are other ways that might also be faster, but I don't have time to explore those right now.

提交回复
热议问题