I had a underscore delimited strings that I need to parse out the 3rd value in. In C# you have the nice Split method.
ex: my_string_stuff_biatch_poop
title.Split('_')[2] would grab the value "stuff".
In tSQL there isn't a Split function so i came up with the following:
SUBSTRING(Title,
CHARINDEX('_', Title, CHARINDEX('_', Title) + 1) + 1,
((CHARINDEX('_', Title, (CHARINDEX('_', Title, CHARINDEX('_', Title) + 1) + 1))+1)
- (CHARINDEX('_', Title, CHARINDEX('_', Title) + 1) + 1)) - 1)
Since I did it all on my lonesome I thought I'd publish it. Have fun.
Syntax
SUBSTRING(expression, start, length)
Syntax
CHARINDEX(expression1, expression2 [, start_location])