Solved

Select Query with Multiple Criteria

Posted on 2014-01-16
7
565 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 225 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 33

Expert Comment

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

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 25 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

737 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