SELECT DISTINCT SUBSTRING(somestuff,
CASE
WHEN PATINDEX(‘%X-%’, somestuff) > 0
THEN 3
ELSE PATINDEX(‘%[A-Z]%’, somestuff)
END,
CASE
WHEN PATINDEX(‘%[0-9]%’, somestuff) = 0
THEN LEN(somestuff)
ELSE PATINDEX(‘%[0-9]%’, somestuff) –
CASE
WHEN PATINDEX(‘%X-%’, somestuff) > 0
THEN 3
ELSE PATINDEX(‘%[A-Z]%’, somestuff)
END
END)
Note the extra use of PATINDEX(‘%X-%’, somestuff). This was necessary to remove the prefix indentifier "X-" that was not removed by the use of PATINDEX(‘%[A-Z]%’, somestuff). The other identifiers were (@ and *). There is probably a way to do this easily with a better RegEx, but I am definitely an amateur in that arena.
Hope this info helps. Happy Coding!