Find Null values on every column

  • Comments posted to this topic are about the item Find Null values on every column

  • Kinda neat idea and simple approach.

    However, it seems pointless to include columns that aren't able to be null in the first place. Here's a quick updated version.

    DECLARE @TableName VARCHAR(200)

    SET @TableName = 'MyTableName' --put your table's name here'

    SELECT

    [schema_name] = schema_name(so.[schema_id])

    ,[table_name] = so.name

    ,[column_name] = sc.name

    ,[statements] = 'SELECT [column_name] = ''' + sc.name + ''', [null_rows] = count(1) FROM ' + schema_name(so.[schema_id]) + '.' + so.name + ' WHERE [' + sc.name + '] IS NULL'

    FROM

    sys.objects so

    INNER JOIN

    sys.columns sc ON (so.[object_id] = sc.[object_id])

    WHERE

    so.name = @TableName

    AND sc.is_computed = 0 -- do not check for computed columns

    --AND uid = 5 -- Uncomment if you need to check a specifyc schema

    AND sc.is_nullable = 1

  • Thanks, nice improvement

  • Thanks to both of you.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply