nulls in a table

  • How can i find where there are any nulls in a table.I dont want to check it on ecery column,I would like to check it on entire table.

    Thanks.

  • You should check your table schema to find out which columns are allowed to be 'nullable'. There is a chance these columns have 'NULL' value.

  • any query to get the result?

  • any query get the result?

  • Hi,

    Let's suppose you have a table called Table1 and the columns are Column1, Column2,Column3

    Column1Column2Column3

    -------------------------------

    1NULLtest1

    2test2NULL

    3test3test4

    SELECT * FROM Table1 WHERE column1 IS NULL OR Column2 IS NULL

    Then you will get the following

    Column1Column2Column3

    -------------------------------

    1NULLtest1

    2test2NULL

    Hope that's what you want.

    Thanks.

  • He may have large number columns defined with nullable.

    Load result of sp_columns 'yourtable' into cursor, loop the cursor, find the columns with nullable defined, create dynamic select statement as showed by srgangu and execute it at end of loop.

  • Run the following code produced from below:

    SELECT 'SELECT ''' + COLUMN_NAME + ''', COUNT(*) FROM ' + TABLE_NAME + ' WHERE ' + COLUMN_NAME + ' IS NULL;'

    FROM INFORMATION_SCHEMA.COLUMNS

    WHERE IS_NULLABLE = 'YES'

    AND TABLE_NAME = 'YOUR_TABLE_NAME'

    ORDER BY TABLE_NAME, ORDINAL_POSITION;

  • In the case of the null able fields have blank, tab, line feed or even carriage return and a ' ' characters, the following code may be help:

    replace(replace(replace(replace(ltrim(rtrim(YourFieldName)),char(9),''),char(10),''),char(13),''),' ','')

  • too bad, the square box could not be display here.

    replace(replace(replace(replace(ltrim(rtrim(YourFieldName)),char(9),''),char(10),''),char(13),''),'SQUARE BOX','')

Viewing 9 posts - 1 through 8 (of 8 total)

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