Solved

Simple SQL Select question

Posted on 2007-04-09
2
220 Views
Last Modified: 2013-12-24
I have a table that has a RecStatus field in it.  For certain record types, the RecStatus is empty.
When I run the sample queries below, only the records with a RecStatus <> Imported or Pursuing are returned. (ie. RecStatus=Maintaining or New are returned)  The records where RecStatus is empty are also not returned.  Can someone tell me why?  Can someone tell me how to fix?  I need the empty RecStatus records as well.

Sample 1:
<cfquery name="sqlAccounts" datasource="#Request.SomeDSN#">
SELECT * FROM tblAccts WHERE RecStatus <> 'Imported' AND RecStatus <> 'Pursuing'
</cfquery>
Sample 2:
<cfquery name="sqlAccounts" datasource="#Request.SomeDSN#">
SELECT * FROM tblAccts WHERE RecStatus NOT IN('Imported','Pursuing')
</cfquery>
0
Comment
Question by:sulzener
2 Comments
 
LVL 3

Accepted Solution

by:
JipFromParis earned 500 total points
ID: 18878038
I assume the RecStatus column allow NULL values. NULL values never match any predicate in a WHERE clause, albeit the IS NULL predicate. So, you should rewrite the first request as :

SELECT * FROM tblAccts WHERE (RecStatus <> 'Imported' AND RecStatus <> 'Pursuing') OR (RecStatus IS NULL)
0
 

Author Comment

by:sulzener
ID: 18878550
Thanks ... Not sure that has ever registered with me before.  Thanks for clearing that up.
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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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