sql query

Hi,
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
AMERICAS        EMMZZZ
AAPACII         EMMZARO
motioneyeAsked:
Who is Participating?
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 ChongCommented:
try use OR:

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

or:

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

?
0
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.
0
gplanaCommented:
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.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

motioneyeAuthor Commented:
Hi,
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
AMERICAS        EMMZZZ
AAPACII         EMMZARO
AAPACII                 EMMZZZ
AMERICAS              EMMKZY
AAPACII         EMMZARO
0
Ryan ChongCommented:
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:
https://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like
0
gplanaCommented:
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.
0

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  
where
    ( ([AD Domain] ='AAPAC' and [ADACCTName]='EMMKZY') or
      ([AD Domain] ='AMERICAS' and [ADACCTName]='EMMZZZ') )
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
motioneye, do you still need help with this question?
0
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.

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.