DECLARE @String nvarchar(200) = 'I_love_my_country' SELECT left(@String, charindex('_', @String) - 1) AS first_element SELECT reverse(left(reverse(@String), charindex('_', (reverse(@String))+'_' ) -1)) AS last_element