Curtis Long
asked on
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,
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,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can use the LIKE operator
WHERE contract LIKE '%ac%'
WHERE contract LIKE '%ac%'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Except one small thing, that returns ac AND acd. How can I exclude acd??