SQL 2008 query

I have a table called plants a column called contract.

In this column I have numbers like the following:

1547ac
154667ac
1445478acd
1245acd
1245ar

I need to write a query that will return all contracts with ac in them.

I know that if I had just the ac or acd etc in the column I could write a query as follows:

select contract
from dbo.plant
where contract ='ac'

But how can I get all contracts with ac in them even if the first portion of the column is anywhere from 4 to 10 numbers then the letters??

Thanks,


Curtis LongAsked:
Who is Participating?
 
tigin44Connect With a Mentor Commented:
WHERE contract LIKE '%ac%'
  AND contract NOT LIKE '%acd%'
0
 
Ariful AmbiaConnect With a Mentor Head of MISCommented:
select contract
from dbo.plant
where contract like '%ac%'
0
 
Curtis LongAuthor Commented:
Thanks!!  

Except one small thing, that returns ac AND acd.  How can I exclude acd??
0
 
tigin44Commented:
you can use the LIKE operator

WHERE contract LIKE '%ac%'
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.