I am working with a database of products, trying to extract the product color from a combined ID/color code column where the color code is always the string following the last hyphen in the column. The issue is that the number of hyphens, product ID, and color code can all be different.
Here are four examples:
ABC123-001
BCD45678-0165
S-XYZ999-M2235
A-S-ABC123-001
The color codes in this case would be 001
, 0165
, M2235
, and 001
. What would be the best way to select these into their own column?
It is great to check whether the hyphen exists or not in the string, to avoid the following error:
I think the following does what you want:
In the event that you might have no hyphens in the value, then use a
case
: