sqlsql-server-2012jet

split column after first delimiter


I need this string to split after the first '-' as follows:

DISPLAY VALUE
466500-GO-INF-ITAPPS-EMP-CLERADM

DISPLAY VALUE2
GO-INF-ITAPPS-EMP-CLERADM

I've tried substring and charindex with no success.


Solution

  • I think stuff() is convenient for this:

    select stuff(value, 1, charindex('-', value), '')