I have the following string:
bzip2,1,668,sometext,foo,bar
How can I SELECT only sometext,foo,bar? The length of the string pre
Code:
declare @input varchar(max) = 'bzip2,1,668,s,o,m,e,t,e,x,t,f,o,o,b,a,r'
--declare @input varchar(max) = 'bzip2,,'
declare @thirdCommaPosition int = nullif(charindex(',', @input, nullif(charindex(',', @input, nullif(charindex(',', @input, 1),0)+1),0)+1 ),0)
select stuff(@input, 1, @thirdCommaPosition, '')
Output:
s,o,m,e,t,e,x,t,f,o,o,b,a,r
Edit
Added nullif's to the third comma calculation part, without them it's possible to get inconsistent results.