日期:2014-05-18  浏览次数:20464 次

排除不想要的字符
我现在只想要0、1、2、3、4、5、6、7、8、9和小数点,其他的字符不要。SQL Server Business Intelligence Development Studio可以做到吗?

------解决方案--------------------
SQL code

declare @str varchar(100)
declare @i int
set @str = 'dfji2349234.sfk23rd'
set @i = patindex('%[^1-9,^.]%',@str)

while @i>0
begin
    set @str = stuff(@str,patindex('%[^1-9,^.]%',@str),1,'')
    set @i = patindex('%[^1-9,^.]%',@str)
end

select @str

/************

----------------------------------------------------------------
2349234.23

(1 行受影响)