asifa
asifa

Reputation: 771

SQL like query not returning correct result

I am using sql server. I have a table

Company
 ABC
 XYZ
 ABC,XYZ

When I run a like query where company like '%ABC%' I get the record containing only ABC and not ABC,XYZ

How to get both the records?

Upvotes: 0

Views: 934

Answers (3)

NG.
NG.

Reputation: 6043

select company from tablename where company like '%ABC%'

it would work irrespective of presence of comma or any other character

Upvotes: 1

Taryn
Taryn

Reputation: 247610

First, you should not contain comma separated list in one column. Doing so, you will run into issues trying to query the data.

Second, your code should work:

select *
from t
where company like '%ABC%'

See a SQL Fiddle with a Demo

Upvotes: 7

juergen d
juergen d

Reputation: 204746

Your query should work. See this example

Upvotes: 2

Related Questions