Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Select Query with Multiple Criteria

Posted on 2014-01-16
7
Medium Priority
?
572 Views
Last Modified: 2014-01-18
I'm having trouble zeroing in on the correct format for a select query with multiple criteria. I currently have the following statement:
sql = "SELECT COUNT(*) FROM memberLogin WHERE (((memberLogin.memberID) = '" & memID & "'));"

Open in new window

I need to add a second criteria.
0
Comment
Question by:slegy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 34

Expert Comment

by:Big Monty
ID: 39787106
this should get you going:

sql = "SELECT COUNT(*) FROM memberLogin WHERE memberLogin.memberID = '" & memID & "' or memberLogin.memberID = 100 or memberLogin.memberID = 101;"

i removed some of the parenthesis as you did not need them
0
 
LVL 34

Accepted Solution

by:
Big Monty earned 900 total points
ID: 39787109
if you want to use variables, simply change it to:

sql = "SELECT COUNT(*) FROM memberLogin WHERE memberLogin.memberID = '" & memID & "' or memberLogin.memberID = '" & memID2 & "' or memberLogin.memberID = '" & memID3 & "';"

of course, you'll want to sanitize the data before using it, as someone can easily do a sql injection. but this should get you started
0
 

Author Comment

by:slegy
ID: 39787134
I get a little confused with all the & and apostrophes. Here is what I want to do:
sql = "SELECT COUNT(*) FROM memberLogin WHERE (memberLogin.memberID = '" & memID & "' and memberLogin.provider = '" & social_provider & "')"

Open in new window

Have I coded the second criteria correctly?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Big Monty
ID: 39787222
Yes that is correct
0
 
LVL 48

Assisted Solution

by:Dale Fye
Dale Fye earned 100 total points
ID: 39787291
Assuming that MemberID and Provider are both strings, Yes.

I would have assumed that MemberID would be numeric.  If that is the case, then you should use:

sql = "SELECT COUNT(*) FROM memberLogin " _
     & "WHERE memberLogin.memberID = " & memID _
     & " AND memberLogin.provider = '" & social_provider & "'"

I've removed the extra set of ( ) around the arguments inside the WHERE clause, those are not needed.

Dale
0
 
LVL 1

Expert Comment

by:MarvinM80
ID: 39787302
Slegy,

Don't forget the ";" at the end.
I also like to capitalize the "AND" (or "OR") just like Dale did. It helps to avoid confusion.

Marvin
0
 

Author Closing Comment

by:slegy
ID: 39791112
Thank you. The ID is alphanumeric. Everything is working great.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

598 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