Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Searching for a particular name

Author  Topic 

Slingerz
Starting Member

2 Posts

Posted - 2014-04-28 : 09:08:53
hey all

i need help with my SQL code, i need to search for a name of a company in the DB but the company name can be written in many formats such as ABC Inc. ABC international, Abc Ltd etc.

I basically want a return on everything that starts with Abc.

I have my WHERE clause so it reads customers.name LIKE '%ABC%' but that is not returning all of the records that I would expect it to.

any ideas? Thanks!

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-04-28 : 09:50:26
Assuming no prefix:

LIKE 'ABC%'

With possible blanks before the name:

WHERE ltrim(customers.name) LIKE 'ABC%'

but that could run a lot slower since the function call to LTRIM stops SQL from using any index on the "name" column.
Go to Top of Page

Slingerz
Starting Member

2 Posts

Posted - 2014-04-28 : 09:52:37
thanks i am going to give it a whirl!
Go to Top of Page

mwendecker
Starting Member

3 Posts

Posted - 2014-04-28 : 21:49:28
IF you have a leading blank it could be LIKE '_ABC%'
Go to Top of Page
   

- Advertisement -