Waller Waller - 4 months ago 7
SQL Question

SQL string manipulation [Get all text left of '(']

I have some data which looks like so:

SourceOfBooking
----------------
Company1 (Foo)
Company2 (Bar)
Company3 (Foo1)
Company4 (Foo2)


I am looking to transform this, so my data only displays:

SourceOfBooking
----------------
Company1
Company2
Company3
Company4


I have tried:

LEFT(SourceOfBooking, CHARINDEX(';', SourceOfBooking) )


with no luck.

I'm sure I'm missing something incredibly simple... Anyone care to enlighten?

KR, James.

Answer

I think you've just put a wrong character

case
    when CHARINDEX('(', SourceOfBooking) > 0 then
        rtrim(left(SourceOfBooking, CHARINDEX('(', SourceOfBooking) - 1))
    else
        SourceOfBooking
end