2

I use SQL Server 2014.

I have string like this:

A.U.TCZ.160001.AC 

I need to get substring between 3rd and 4th occurrence of ., so in this example I should get 160001

Jande
  • 1,695
  • 2
  • 20
  • 32
user1762186
  • 190
  • 2
  • 6
  • 16

1 Answers1

3
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)

More generic way how to do it you may find in this SO question

Community
  • 1
  • 1
kurin123
  • 363
  • 1
  • 6