Substring and CharIndex

Use a string splitter such as from here and pick the fourth value from the result of the split.

An alternative, even though it looks a little ugly is described here If you were to use that, it would be like this:

DECLARE @x VARCHAR(64) = '123_234_234_345_34A_456'

SELECT
	[Part_5] = LEFT(e,CHARINDEX('_',e+'_')-1)
FROM
	( VALUES (@x) ) A(a)
	CROSS APPLY (VALUES (STUFF(a,1,CHARINDEX('_',a+'_'),''))) B(b)
	CROSS APPLY (VALUES (STUFF(b,1,CHARINDEX('_',b+'_'),''))) C(c)
	CROSS APPLY (VALUES (STUFF(c,1,CHARINDEX('_',c+'_'),''))) D(d)
	CROSS APPLY (VALUES (STUFF(d,1,CHARINDEX('_',d+'_'),''))) E(e);
1 Like