1

I have delimited string like this 'test1:test2:test3:test4:test5'.

I need to get the third and forth values one value at a time. The string always has five values.

Michael Green
  • 25,255
  • 13
  • 54
  • 100
Haya
  • 29
  • 1

1 Answers1

0

You can take a SUBSTRING of your string to ignore the first element, then use PARSENAME. Then, you don't have to use a function.

declare @var varchar(64) = 'test1:test2:test3:test4:test5'

select 
    ThirdElement = parsename(replace(substring(@var,charindex(':',@var) + 1,len(@var)),':','.'),3)
    ,FourthElement = parsename(replace(substring(@var,charindex(':',@var) + 1,len(@var)),':','.'),2)
S3S
  • 3,578
  • 1
  • 14
  • 25