Solved

Using Boolean logic in a SQL statement WHERE statement

Posted on 2013-01-12
3
392 Views
Last Modified: 2013-01-17
I need to select records based on one criteria plus a 2nd variable criteria:

A and (B or C)

Currently my sql statement is:

sql2 = "SELECT COUNT(tblJournal.ChartID) AS CountEBSCO12NoContract " & _
"FROM tblJournal " & _
"WHERE tblJournal.FY12Vendor = 'EBSCO' AND tblJournal.FY12NatContract = 'No' OR " & _
      "tblJournal.FY12Vendor = 'EBSCO' AND tblJournal.FY12NatContact IS NULL "

Set obj2 = Server.CreateObject("ADODB.Recordset")
obj2.Open sql2, objConn


The error generated is:
     Microsoft OLE DB Provider for ODBC Drivers error '80040e10'
     [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
0
Comment
Question by:Malloy1446
[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
  • 2
3 Comments
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 38771069
I don't use access anymore and only sql server.  But I think you need to use isnull(tblJournal.FY12NatContact )

WHERE tblJournal.FY12Vendor = 'EBSCO' AND tblJournal.FY12NatContract = 'No' OR " & _
      "tblJournal.FY12Vendor = 'EBSCO' AND isNull(tblJournal.FY12NatContact  )
0
 

Accepted Solution

by:
Malloy1446 earned 0 total points
ID: 38771074
FIgured it out.  Need to have the OR on the 2nd line of the WHERE statement.

THanks.
0
 

Author Closing Comment

by:Malloy1446
ID: 38786400
I was deleting my question because I found the solution myself. At the same time someone was providing a possible solution.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

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…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

627 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