locked
check for null RRS feed

  • Question

  • how can I make a conditional check on (slection of table) column to see if it contains a null value
    Friday, March 19, 2010 2:18 PM

Answers

  • Hi Hasan,

    select ColumnList From TableName Where ColumnName is Null


    Failure in Life is failure to try...
    • Proposed as answer by Phil Brammer Friday, March 19, 2010 2:37 PM
    • Marked as answer by Dr.X1987 Saturday, March 20, 2010 12:33 PM
    Friday, March 19, 2010 2:22 PM
  • Hasa, you can use IS NULL and IS NOT NULL. Check this code

    DECLARE @t TABLE(ID INT,Value VARCHAR(20))
    INSERT INTO @t
    SELECT 1, 'Test1' UNION ALL SELECT 2,NULL UNION ALL SELECT 3,NULL UNION ALL SELECT 4,'Test2'
    
    SELECT COUNT(*) AS NullValues
    FROM @t
    WHERE Value IS NULL

     


    Abdallah El-Chal, PMP, ITIL, MCTS
    • Proposed as answer by Phil Brammer Friday, March 19, 2010 2:37 PM
    • Marked as answer by Dr.X1987 Saturday, March 20, 2010 12:33 PM
    Friday, March 19, 2010 2:25 PM

All replies

  • Hi Hasan,

    select ColumnList From TableName Where ColumnName is Null


    Failure in Life is failure to try...
    • Proposed as answer by Phil Brammer Friday, March 19, 2010 2:37 PM
    • Marked as answer by Dr.X1987 Saturday, March 20, 2010 12:33 PM
    Friday, March 19, 2010 2:22 PM
  • Hasa, you can use IS NULL and IS NOT NULL. Check this code

    DECLARE @t TABLE(ID INT,Value VARCHAR(20))
    INSERT INTO @t
    SELECT 1, 'Test1' UNION ALL SELECT 2,NULL UNION ALL SELECT 3,NULL UNION ALL SELECT 4,'Test2'
    
    SELECT COUNT(*) AS NullValues
    FROM @t
    WHERE Value IS NULL

     


    Abdallah El-Chal, PMP, ITIL, MCTS
    • Proposed as answer by Phil Brammer Friday, March 19, 2010 2:37 PM
    • Marked as answer by Dr.X1987 Saturday, March 20, 2010 12:33 PM
    Friday, March 19, 2010 2:25 PM