substring or trim a text string up to a specific character

Database
Enthusiast

substring or trim a text string up to a specific character

I am trying to extract only parts of text strings that are of varying length but in each case I am trying to only get only the part of the string that preceeds a specific character.   For example for the string  “one1_YYY” I would want only the “one1” and in “second2-VVV_YYY” I only want “second2-VVV”

To my knowledge substring and trim only work on specific character positions.    Does anyone know of any way to do this?

Thanks

R

1 REPLY
Senior Apprentice

Re: substring or trim a text string up to a specific character

SUBSTRING(col FROM 1 FOR POSITION('_' IN col) - 1)

Dieter