View Single Post

   
  #2 (permalink)  
Old 02-29-2008, 05:11 AM
David Portas
 
Posts: n/a
Default Re: SQL Statement Count NULL Values

Here are two possibilities:

SELECT
CASE WHEN patientid IS NULL THEN 1 ELSE 0 END+
CASE WHEN age IS NULL THEN 1 ELSE 0 END+
CASE WHEN weight IS NULL THEN 1 ELSE 0 END+
CASE WHEN height IS NULL THEN 1 ELSE 0 END+
CASE WHEN race IS NULL THEN 1 ELSE 0 END
FROM tblPatientDemographics

SELECT 5-COUNT(patientid)-COUNT(age)-COUNT(weight)-COUNT(height)-COUNT(race)
FROM tblPatientDemographics
GROUP BY <primary key column(s)>

--
David Portas
SQL Server MVP
--


Reply With Quote