Reputation: 190
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
Upvotes: 2
Views: 12278
Reputation: 363
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
Upvotes: 3