Skip to content
Advertisement

Based on Condition Extract Values Right of String

I have a dataset in sql that looks like this:

If Col1 contains either _DND_ or _ETL_, I want to remove everything to the left of DND_ and ETL_.

Final expected output is below:

I tried below for 1 condition but the result was NULL:

Advertisement

Answer

I would be inclined to use STUFF():

Your code doesn’t work because the LIKE fails unless “DND” starts at the second position. So, it is returning NULL.

Because _ is a wildcard in LIKE, the LIKE pattern escapes it.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement