Groups | Blog | Home
all groups > sql server new users > october 2006 >

sql server new users : NULL in query



Warren Brunk
10/10/2006 10:15:19 AM
You could set the null values to something outside of your where statement
as well using the isNull Function.

SELECT * from MyTable where (NOT (isNull(MyCol,0)=-1))

--
/*
Warren Brunk - MCITP - SQL 2005, MCDBA
www.techintsolutions.com
*/


[quoted text, click to view]

Hilary Cotter
10/10/2006 1:07:15 PM
Try SELECT * from MyTable where MyCol<>-1 or MyCol is null


--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.

This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com



[quoted text, click to view]

Anders Eriksson
10/10/2006 6:15:47 PM
Hello,

I want to make an SQL query that selects all records in a table where a
certain column is NOT -1

The column is an int but may have the value NULL

I have used this SQL statement:

SELECT * from MyTable where (NOT (MyCol=-1))

If I have an integer value in the column then it works, but it will fail on
all where the column value is NULL.

Why isn't NULL != MyCol=-1

What SQL should I use to make this work?

// Anders
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Arto Viitanen
10/11/2006 12:00:00 AM
[quoted text, click to view]


SQL Server uses three value logic (like all other SQL databases):

true, false and NULL

For NOT, the this means that

NOT true is false
NOT false is true
NOT NULL is NULL.

In your case, NULL = -1 is NULL, and NOT NULL is NULL.

For more information, read some database book, or check

http://www.sqlservercentral.com/columnists/mcoles/fourrulesfornulls_printversion.asp


--
Arto Viitanen, CSC Ltd.
Hugo Kornelis
10/14/2006 12:49:29 AM
[quoted text, click to view]

(snip)
[quoted text, click to view]

Hi Arto,

One minor correction - the third value in the logic tables used by SQL
Server (and other SQL databases) is "Unknown", not NULL.

This is a relevant difference, not just nitpicking words, because there
are some rules for NULL that don't apply to the logic value Unknown.

--
Arto Viitanen
10/16/2006 8:53:50 AM
[quoted text, click to view]

Yes, you are right. I have read a master's thesis which describes
different ways to interprete NULL. Unknown is only one of them (but most
common one).

--
Arto Viitanen, CSC Ltd.
Anders Eriksson
10/16/2006 11:36:34 AM
[quoted text, click to view]

This was a bit of a surprise! Can't really figure out why they decided on
this.

Thank you for your answer!

// Anders

// Anders
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
AddThis Social Bookmark Button