SQL 从字符串列中提取多个数值

SQL extract multiple numeric values from string column

我阅读并使用了本文中建议的功能:

http://blog.sqlauthority.com/2008/10/14/sql-server-get-numeric-value-from-alpha-numeric-string-udf-for-get-numeric-numbers-only/

效果很好,但实际上我需要两列的结果(我希望两个数字在原始字符串中用空格和 / 字符分隔)

假设 "nfsdklj6 / 3 ddfsdf" 应该是 6 | 3个 "nfsdklj45 / 100 ddfsdf" 应该是 45 | 100

我是一名菜鸟 sql 程序员,所以任何帮助或提示将不胜感激, 谢谢

如果你使用的是上述的udf

Declare @Table table (MyString varchar(25))
Insert into @Table (MyString) values 
('nfsdklj6 / 3 ddfsdf'),
('nfsdklj45 / 100 ddfsdf')

Select * 
      ,Val1=dbo.udf_GetNumeric(substring(MyString,1,charindex('/',MyString)))
      ,Val2=dbo.udf_GetNumeric(substring(MyString,charindex('/',MyString),50))
 From @Table

Returns

MyString                Val1    Val2
nfsdklj6 / 3 ddfsdf     6       3
nfsdklj45 / 100 ddfsdf  45      100

针对您的具体情况table

Select Shuma 
      ,Val1=dbo.udf_GetNumeric(substring(Shuma,1,charindex('/',Shuma)))
      ,Val2=dbo.udf_GetNumeric(substring(Shuma,charindex('/',Shuma),50))
 From [dbo],[Deals] 
 Where Shuma not like LIKE '%1 / 1%'