Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 615
Waller Avatar asked Oct 15 '12 16:10

Waller


1 Answers

You can;

LEFT(SourceOfBooking, CHARINDEX(' (', SourceOfBooking + ' (') - 1)

(Remove + ' (' if needed; it allows for rows with no  (

like image 148
Alex K. Avatar answered Sep 20 '22 13:09

Alex K.