Solved

Using Boolean logic in a SQL statement WHERE statement

Posted on 2013-01-12
3
388 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
  • 2
3 Comments
 
LVL 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

17 Experts available now in Live!

Get 1:1 Help Now