Skip to content
Advertisement

Returning the column value even if the special character isn’t present using SUBSTRING & CHARINDEX

I’m using SQL and trying to show all the data in a column before a special character like <.

I’ve used this SQL:

It works absolutely fine when there is a < in the column, but when one isn’t present I get no result. I need to be able to return the column value even if the character isn’t present.

I looked at RTRIM, LEFT and LEN functions but as my Activity Name can be different lengths, they didn’t seem to fit.

I’d appreciate any advice.

Advertisement

Answer

I think the simplest fix is to append a '<' to the string:

If you don’t want the '<' in the result, then:

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