【问题标题】:SQL Server : select text between 3rd and 4th occurrence of '.'SQL Server:选择“。”的第 3 次和第 4 次出现之间的文本
【发布时间】:2016-07-13 04:30:30
【问题描述】:

我使用 SQL Server 2014。

我有这样的字符串:

A.U.TCZ.160001.AC 

我需要在 . 的第 3 次和第 4 次出现之间获取子字符串,所以在这个例子中我应该得到 160001

【问题讨论】:

    标签: sql-server substring sql-server-2014


    【解决方案1】:
    Declare @text varchar(100) = 'A.U.TCZ.160001.AC'
    
    Declare @3rd int
    Declare @4th int
    
    Select @3rd = charindex('.',@text,charindex('.',@text,charindex('.',@text)+1)+1)
    Select @4th = charindex('.',@text,@3rd+1)
    Select Substring(@text, @3rd+1, @4th-@3rd-1)
    

    您可以在SO question 中找到更通用的方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多