SQL 2008 query

Posted on 2011-10-27
Last Modified: 2012-05-12
I have a table called plants a column called contract.

In this column I have numbers like the following:


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??


Question by:HDM
    LVL 4

    Assisted Solution

    by:Ariful Ambia
    select contract
    from dbo.plant
    where contract like '%ac%'

    Author Comment


    Except one small thing, that returns ac AND acd.  How can I exclude acd??
    LVL 26

    Expert Comment

    you can use the LIKE operator

    WHERE contract LIKE '%ac%'
    LVL 26

    Accepted Solution

    WHERE contract LIKE '%ac%'
      AND contract NOT LIKE '%acd%'

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now