Solved

Select Query with Multiple Criteria

Posted on 2014-01-16
7
559 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
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

773 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