SQLTeam.com | Weblogs | Forums

Validating population of a column in a stored procedure


#1

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.


#2

Synthetic example will do.


#3

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

#4

Thank you...I will try that. I appreciate it.