Solved

Select Query with Multiple Criteria

Posted on 2014-01-16
7
551 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 32

Expert Comment

by:Big Monty
Comment Utility
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 32

Accepted Solution

by:
Big Monty earned 225 total points
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
Yes that is correct
0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 25 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you. The ID is alphanumeric. Everything is working great.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now