在给定的字符串BT逗号查找字符串分隔

问题描述:

我需要从字符串中获得第三子串下面是样品,使用SQL Server 2008在给定的字符串BT逗号查找字符串分隔

字符串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

STRING3: -

('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

预先感谢。

+2

[你有什么**尝试?](http://www.whathaveyoutried.com) – 2013-02-10 10:50:19

+0

这看起来更像是得到第三列,而不是第三个子字符串... – clapas 2013-02-10 11:51:05

尝试这样:

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 Fiddle example