?
Solved

Select Query with Multiple Criteria

Posted on 2014-01-16
7
Medium Priority
?
569 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 33

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 33

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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 33

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

771 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