在字符串中捕获字符串

我正在尝试从文本字符串中解析出值。这些值嵌套在字符串中。例如,我得到的平面文件如下所示:“ John Q Public(12345-01)-客户推荐”。我想解析帐号;例如12345-01,来自文本字符串。起始位置不固定,帐号长度也不固定。模式是#####-##。

任何帮助将不胜感激。

wxfjf200806 回答:在字符串中捕获字符串

一些基本的字符串操作将捕获所需的值。不知道这在您的实际情况下是否可行,因为我不知道您的数据有多“稳定”或一致。

declare @Something varchar(100) = 'John Q Public (12345-01) - Customer referral'

select substring(@Something,charindex('(',@Something) + 1 --starting position of the values you want,charindex(')',@Something) - charindex('(',@Something) - 1 --length of the values you want
    ) 
本文链接:https://www.f2er.com/3078925.html

大家都在问