Solved

Using Boolean logic in a SQL statement WHERE statement

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide cell in a table 2 27
Obtain data from database .mdb 4 20
Time comparison asp 1 16
Stored Procedure needs owner to execute 5 24
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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