Get string between 2 characters that repeats several times in sql server

0

Please login or register to vote for this query.

(click on this box to dismiss)

Robotics Meta

Q&A about the site for professional robotic engineers, hobbyists, researchers and students

DECLARE @t table(id int, myString varchar(40))
INSERT @t 
VALUES (1,'aaa|bb|ccc(ddd)'),(2, 'eeee(ff)gggg(hhh)iii')

SELECT id, stuff(value, 1, charindex('|',value),'') myString
FROM 
  @t t
CROSS APPLY
  STRING_SPLIT(mystring,'|') 
WHERE value like '%|%'
ORDER BY id

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results