?
Solved

SQL 2008 query

Posted on 2011-10-27
4
Medium Priority
?
231 Views
Last Modified: 2012-05-12
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,


0
Comment
Question by:Curtis Long
  • 2
4 Comments
 
LVL 4

Assisted Solution

by:Ariful Ambia
Ariful Ambia earned 400 total points
ID: 37038996
select contract
from dbo.plant
where contract like '%ac%'
0
 

Author Comment

by:Curtis Long
ID: 37039026
Thanks!!  

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

Expert Comment

by:tigin44
ID: 37039032
you can use the LIKE operator

WHERE contract LIKE '%ac%'
0
 
LVL 26

Accepted Solution

by:
tigin44 earned 1600 total points
ID: 37039042
WHERE contract LIKE '%ac%'
  AND contract NOT LIKE '%acd%'
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

807 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