0

我只是想从下面列出的字符串中返回订单号。我已经尝试使用左右和子字符串的 charindex 无济于事。使用实际数据,订单号可以是 9 到 12 个字符。

Declare @string varchar(max) = 'Your order number for this purchase is 012345678 and we appreciate your business'

非常感谢任何帮助。

在此先感谢,M.Butter

4

1 回答 1

0

PATINDEX可用于进行正则表达式搜索以查找订单号

%[0-9]%

找到索引后,可以使用 SUBSTRING 获取订单号

declare @var varchar(max) = 'Your order number for this purchase is 012345678 and we appreciate your business'

declare @sub varchar(max)
select @sub=SUBSTRING(@var,patindex('%[0-9]%', @var), len(@var))

SELECT SUBSTRING(@sub, 0, charindex(' ', @sub))  
于 2014-10-17T22:05:13.157 回答