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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Display the NULL

Status
Not open for further replies.

gio2888

Technical User
Oct 26, 2000
64
US
heres a SQL statement...
SELECT * FROM portal_main P, portal_cat_title C WHERE P.category = C.category AND ( ( name like '%fyi%' ) OR ( portal_keywords like '%fyi%' ) ) AND ((P.unit_id = '') OR (unit_id like '%NEB%')) OR (unit_id like '%NULL%') ORDER BY name

I want the results to show all the ones with unit_id being blank, NEB, and NULL. I couldn t get it to show the NULLs, I got the blank ones and the NEB ones. Thanks in advance!
 
Try changing that last bit to this:

((P.unit_id = '') OR (unit_id like '%NEB%') OR (unit_id is NULL))

Note I also moved the closing parenthesis...Looks like that's what you were going for.
 
It didn t work, only the ones with "NEB" and blanks showed up.
 
skicamel is right.
You have to use special syntax to deal with NULL values. In this case it is the 'IS NULL' syntax.
You can test this on your table just by doing
select * from portal_main where unit_id is null
This should return all the rows where unit_id has a NULL value.
 
I may have made the wrong assumption w/ moving the parenthesis. This has your original grouping w/ the new syntax. Hope this works for you.

SELECT * FROM portal_main P, portal_cat_title C
WHERE P.category = C.category
AND
(( name like '%fyi%' ) OR ( portal_keywords like '%fyi%' ))
AND
((P.unit_id = '') OR (unit_id like '%NEB%'))
OR
(unit_id is NULL)
ORDER BY name
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top