views:

142

answers:

2

I am trying to select all rows from a database where display = 'Y' and announcement != null. How can I check a column to make sure it contains a value?

 $qry = "select * 
         from  school
  where  display='Y'
  order by name, announcement, last_update";
+4  A: 
$qry = "select *       
         from   school
         where  display='Y'
         and (announcement != '' AND announcement IS NOT null)
         order by name, announcement, last_update";

This caters for blank fields as well as null fields.

ChristianLinnell
the standard SQL way is that any statement that contains NULL should return null, which is why you have use IS NOT NULL or ISNULL()
nickf
Updated. Do your comments still apply?
ChristianLinnell
nope - you've got it right now.
nickf
+3  A: 
announcement IS NOT NULL

or

NOT ISNULL(announcement)
nickf