Solved

Using Boolean logic in a SQL statement WHERE statement

Posted on 2013-01-12
3
386 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

20 Experts available now in Live!

Get 1:1 Help Now