I am working on a stored procedure that requires validating if a particular field has any nulls or is 100% populated. Using the system tables, I have created code to verify that my database, table and column exists. Because of the nature of the data with which I work, I cannot provide an example. What I am needing is the snippet of code that would determine if the column name has any nulls. I have @SQL variable created, and am just unsure how to structure the query so that I can validate the population of the field. Any suggestions? I have to validate this for 2 fields, and would prefer a query that allows me to perform this in one statement.
Synthetic example will do.
The general query structure would be:
SELECT SUM(CASE WHEN column_name1 IS NULL THEN 1 ELSE 0 END) AS column1_NULL_count, SUM(CASE WHEN column_name2 IS NULL THEN 1 ELSE 0 END) AS column2_NULL_count, SUM(1) AS total_rows FROM dbo.table_name
Thank you...I will try that. I appreciate it.