Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

Split string and get first and last element in sql server

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 
 
PREVIOUS NEXT
Tagged: #Split #string #element #sql #server
ADD COMMENT
Topic
Name
8+2 =