简体   繁体   English

如何从SQL Server 2005或2008中的原始字符串输入中删除不是数字的任何内容

[英]How to remove anything that is not a number from a raw string input in SQL Server 2005 or 2008

Is there an efficient way using sql server 2005 to remove all characters in a string like this which are not numbers? 有没有一种有效的方法使用sql server 2005来删除字符串中不是数字的所有字符?

TEXT T EXT TEXT 2345 TEXT SDTE

I was thinking there might be a way to combine the replace statement with a regular expression. 我在想可能有一种方法可以将replace语句与正则表达式结合起来。

Here is the answer from the related question , with the slight change needed to remove non-numbers as opposed to non-alphas: 这是相关问题答案 ,与删除非数字(与非字母)相反,需要稍作更改:

Create Function [dbo].[RemoveNonNumericCharacters](@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin

    While PatIndex('%[^0-9]%', @Temp) > 0
        Set @Temp = Stuff(@Temp, PatIndex('%[^0-9]%', @Temp), 1, '')

    Return @Temp
End

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM