I have column which has – as delimeter and i want to get substring between first delimeter and second delimeter
ABC-DEF-FG
ABCD-JAFF-UIOU-TYU
Output
DEF
JAFF
I have tried substring and charIndex but not getting exactly what i wanted
select * SUBSTRING(column, CHARINDEX('-', column)+1, len(column)) from table
select * SUBSTRING(column, CHARINDEX('-', column)+1, charindex('-', column, (charindex('-', column, 1)))) from table
select * SUBSTRING(column, CHARINDEX('-', column)+1, charindex('-', column, (charindex('-', column, 1))+1)) from table
>Solution :
With a bit of JSON
Example
Select A.[column]
,Pos2 = JSON_VALUE(S,'$[1]')
From YourTable A
Cross Apply ( values ( '["'+replace(string_escape([column],'json'),'-','","')+'"]' ) ) B(S)
Results
column Pos2
ABC-DEF-FG DEF
ABCD-JAFF-UIOU-TYU JAFF