Seems like a lot of coding when generally speaking the best way to deal with the NULL values is in a where clause. What lingers in all of these solutions is the lack of a where clause. Remove the NULLS in the where clause and the count will work more naturally.
Select count(distinct field_value) where field_value is NOT NULL