Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exclude null values

Status
Not open for further replies.

newtosql

Programmer
Joined
Apr 7, 2003
Messages
18
Location
US
Im new to sql and Id like to exclude null values from my query. When I run my query (in query analyzer) I still see the null values that I want to exclude.

select col_a
from tabl_a (nolock)
where (NOT (col_b IS NULL))

Any ideas? Thanks guys.
 
I'm not quite sure why you would want to use the "nolock" statement this way, but the code

select col_a
from table (nolock)
where col_b is not null

should work (also without "(nolock)")

Good luck!

Lara
 
Hi,

Try the following:

SELECT
col_a
FROM
Table_a
WHERE
col_b IS NOT NULL
 
Hmm, that doesnt work. Im still seeing NULLs in my results set in query analyzer. Its a datetime column.

Is there anything else I should be trying?
 
by the way...when I use this query in a View, my query doesnt return any null values (which is what I want). So why doesnt this work in query analyzer?
 
This might sound a bit stupid but are you seeing nulls in the selected column a ?

If so the query may well return null values in column a as your where clause is where column b is null not column a.

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top