• Here's something that might get you started:

    ;WITH NullableColumns AS (

    SELECT TableName=a.name, ColName=b.name

    FROM QA.sys.objects a

    INNER JOIN QA.sys.all_columns b

    ON a.object_id = b.object_id

    WHERE is_nullable = 0 and type = 'U'

    )

    SELECT 'SELECT ' +

    STUFF((

    SELECT ',' + ColName

    FROM NullableColumns b

    WHERE a.TableName = b.TableName

    FOR XML PATH(''))

    ,1, 1, '') +

    ' FROM ' + TableName +

    ' WHERE ' +

    STUFF((

    SELECT ' AND ISNULL(' + ColName + ','''') <> '''''

    FROM NullableColumns b

    WHERE a.TableName = b.TableName

    FOR XML PATH(''), TYPE).value('.', 'VARCHAR(MAX)')

    ,1, 5, '')

    FROM NullableColumns a

    GROUP BY TableName

    This generates SQL statements for every table in the database that you run it in that will select out any columns where NULL is not allowed if the value in a row is NULL, '' or ' '.

    You could put the results into a temp table and iterate through that to execute each of the SQL statements.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St