0

我需要从下面的字符串中获取第三个子字符串是示例,使用 SQL Server 2008。

字符串1:-

('C20080703115333MCTTtettett','24','6101349328','Bundled Standard','4','2.00','Testing Insert for New SP',','PD2013021002584832540')

期望的结果:- 6101349328

字符串2:-

('C20080703115333MCTTetew','24','7101349328','Bundled Standard','4','2.00','Testing Insert for New SP',','PD2013021002584832540')

期望的结果:- 7101349328

字符串3:-

('C20080703115333MCTTteetew','24tt','8101349328','Bundled Standard','4','2.00','Testing Insert for New SP',','PD2013021002584832540')

期望的结果:- 8101349328

字符串4:-

('C20080703','24','111101349328','Bundled Standard','4','2.00','Testing Insert for New SP',','PD2013021002584832540')

期望的结果:- 111101349328

提前致谢。

4

1 回答 1

0

尝试这样的事情:

select val = substring
  (
    str
    , charindex(',', str, charindex(',',str, 0) + 1) + 2
    , charindex(',', str, charindex(',', str, charindex(',',str, 0) + 1) + 1)
       - (charindex(',', str, charindex(',',str, 0) + 1) + 3)
  )
from strings

这使:

6101349328
7101349328
8101349328
111101349328

SQL 小提琴示例

于 2013-02-10T10:56:15.310 回答