sql query

How do I query a single table with two column in where clause  for a multiple values ? I have a value with me in where cluse but not sure how to put this in construct query

The where clause must be a combination of two column within a table , the query below works with only per row ouput, but how I have this for multiple value ?

select * from VemployeeDisc  where [AD Domain] ='AAPAC' and [ADACCTName]='EMMKZY'

[AD Domain]      [ADACCTName]
AAPAC           EMMKZY
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try use OR:

select * from VemployeeDisc  where [AD Domain] ='AAPAC'  OR [ADACCTName]='EMMKZY'


select * from VemployeeDisc  where [AD Domain] in ('AAPAC','EMMKZY')  OR [ADACCTName] in ('AAPAC','EMMKZY')

Naitik GamitSoftware DeveloperCommented:
AND Return value if both AD Domain and ADACCTName satisfy,
If you want to return any of them you can use OR,IN,Between functions as per Ryan Chong solution.
Ryan Chong is right: you should use OR instead of AND, because for a value is impossible to be equal to two different values at the same time.

There is a better syntax for what you want, specially if you need to put more values. This is by using IN operator (instead of equal) which allows you to put a list of values separated by commas. Then, your previous example would be:

select * from VemployeeDisc  where [AD Domain] IN ('AAPAC', 'EMMKZY')

Open in new window

Hope this helps. Regards.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

motioneyeAuthor Commented:
Actually in the table it self we have multiple values as below and the problems is I need to select maybe around 20-30 records  for an ad-hoc request from user

[AD Domain]      [ADACCTName]
AAPAC           EMMKZY
AAPACII                 EMMZZZ
AMERICAS              EMMKZY
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
if you are comparing similar values in a field, you probably can use Like clause instead.

for example:

select * from VemployeeDisc  where [AD Domain] like '%AAPAC%'  OR [ADACCTName] like '%EMM%'

for more info:
Or you can teach user to user SQL and let user copy and paste the syntax I have put above, so they just have to change the values inside the IN operator.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott PletcherSenior DBACommented:
If you have multiple specific column combinations, you need to do something like this:

select *
from VemployeeDisc  
    ( ([AD Domain] ='AAPAC' and [ADACCTName]='EMMKZY') or
      ([AD Domain] ='AMERICAS' and [ADACCTName]='EMMZZZ') )
Vitor MontalvãoMSSQL Senior EngineerCommented:
motioneye, do you still need help with this question?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.