【问题标题】:Finding string in given set of strings bt comma separated在给定的字符串集中查找字符串 bt 逗号分隔
【发布时间】:2013-02-10 10:34:35
【问题描述】:

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

string1:-

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

想要的结果:- 6101349328

string2:-

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

string4:-

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

想要的结果:- 111101349328

提前致谢。

【问题讨论】:

标签: sql-server sql-server-2008 substring


【解决方案1】:

试试这样的:

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.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    相关资源
    最近更新 更多