473,657 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL statement with <> and Null values in the table

I have the following SQL statement in code:

strSQL = "SELECT * FROM TABLEA WHERE F2 = 'SITE'

This returns the record that I expect.

However: the following does not

strSQL = "SELECT * FROM TABLEA WHERE F2 <'SITE'
But if I rewrite it as:

strSQL = "SELECT * FROM TABLEA WHERE Nz(F2,'') <'SITE'

that seems to retrieve records where there may be nulls in column F2.

Let me just say that this table is a holding table for an Excel import so
values could be anything.

Is this correct. That is, I have to use the Nz function when using <>. I
haven't been doing this in some other SQL queries and now realize that I may
be missing some rows that should be returned.

Can someone explain this to me?

Thanks.

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200610/1

Oct 23 '06 #1
1 1596

rdemyan via AccessMonster.c om wrote:
I have the following SQL statement in code:

strSQL = "SELECT * FROM TABLEA WHERE F2 = 'SITE'

This returns the record that I expect.

However: the following does not

strSQL = "SELECT * FROM TABLEA WHERE F2 <'SITE'
But if I rewrite it as:

strSQL = "SELECT * FROM TABLEA WHERE Nz(F2,'') <'SITE'

that seems to retrieve records where there may be nulls in column F2.

Let me just say that this table is a holding table for an Excel import so
values could be anything.

Is this correct. That is, I have to use the Nz function when using <>. I
haven't been doing this in some other SQL queries and now realize that I may
be missing some rows that should be returned.

Can someone explain this to me?

Thanks.
null is not comparable to anything: it is the void.

null = null equates to false
null <null will also be false
something = null will return false
something <null will likewise be false

Something + null equates to null; the only operator that breaks the
rule is the ampersand concatenation operator &

the only way to work with a null is to test for nullness, and match on
the resultant, or convert the null to some other value..
nz() is a shorthand for iif(isnull(vari able),substitut e,variable)

So yes, if you have nulls, but want to equate them with something else,
you have to convert them, as in the examples below

strSQL = "SELECT * FROM TABLEA WHERE F2 <'SITE" or F2 is NULL"'
strSQL = "SELECT * FROM TABLEA WHERE F2 & "" <'SITE'"
as well as your
strSQL = "SELECT * FROM TABLEA WHERE Nz(F2,'') <'SITE'"

Oct 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3209
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are writing one object in C# which will take the entire table tag contents and renders. Ie., we need to pass "<table>………… <thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
2
10555
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script type="text/javascript"> <!]> </script> <script type="text/javascript"
4
21425
by: PASQUALE | last post by:
Hi I have a question: do the both statements below give the same result? If yes then does somebody know something about preformance differencies using these joins? SELECT A.* FROM Table1 A INNER JOIN Table2 B on A.Field1 <> B.Field1
1
1178
by: bshort1023 | last post by:
I have text field with 3 possible values: C, F, or Null. When I query with criteria: Not "C", I get only the F records and not the Nulls. Is this normal? I have been working with a SQL table through ODBC and when I use Not "C" on that table I get the F records and the Null records. When I do it against an Access table with the same field properties I get the above results.
22
3494
by: amygdala | last post by:
Hi, I'm trying to grasp OOP to build an interface using class objects that lets me access database tables easily. You have probably seen this before, or maybe even built it yourself at some point in time. I have studied some examples I found on the internet, and am now trying to build my own from scratch. I have made a default table class (DB_Table), a default validation class (Validator) which is an object inside DB_Table and my...
3
3367
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt, &gt ,&ltCompany&gt to display '<', '>' and '<Company>' respectively. But is there any freeware code available which could implement the above functionality without having to use &gt,&lt and such stuff???
6
1840
by: Kbalz | last post by:
Trying to run a simple query on my dataset the SQL statement looks like this: select * from person where id in (@p) When using more than one id in the "in statement", I get nothing! Using Visual Studio interface, there is the Execute Query button in Query Builder. Here I can set @p = 1, and the test execute returns the row where id = 1.. and I can do the same for @p = 2.
1
4365
zachster17
by: zachster17 | last post by:
Hello all, I'm trying to write a multi-statement table function that returns a table of addresses from a remote database (Oracle) using OpenQuery and I'm having a hard time getting it to work with the 1 variable constraint it has (provider ID) The code is below: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON
8
4012
by: michael | last post by:
Hi all A client of mine is having a problem with their site and when I looked into the SQL database, I found that most text fields have been altered and appended with script src=http://www.westpacsecuresite.com/b.js/script I've taken out the < so that this shows.
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7333
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1957
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.