locked
Null value c# RRS feed

  • Question

  • User410067686 posted

    How do you select a column that is NULL data value in the database?

    Monday, July 14, 2014 12:54 PM

Answers

  • User281315223 posted

    You could use something like :

    SELECT * 
      FROM YourTable
     WHERE YourColumn IS NULL

    Or if you were using something like LINQ :

    var nullValues = YourContext.YourTable.Where(x => x.YourColumn == null);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 14, 2014 1:18 PM

All replies

  • User281315223 posted

    You could use something like :

    SELECT * 
      FROM YourTable
     WHERE YourColumn IS NULL

    Or if you were using something like LINQ :

    var nullValues = YourContext.YourTable.Where(x => x.YourColumn == null);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 14, 2014 1:18 PM
  • User-1716253493 posted

    replace null with empty string using IsNull function

    SELECT * FROM TBL WHERE ISNULL(Fieldname,'') = ''

    http://msdn.microsoft.com/en-us/library/ms184325.aspx

    Monday, July 14, 2014 11:27 PM
  • User-158764254 posted

    replace null with empty string using IsNull function

    SELECT * FROM TBL WHERE ISNULL(Fieldname,'') = ''

    http://msdn.microsoft.com/en-us/library/ms184325.aspx

    This is something you should strive to never do as it is considered non-sargable (http://en.wikipedia.org/wiki/Sargable).  It requires your query to operate as a table scan and perform a function on each and every row of data in the table - with no ability to take advantage of indexes.

    Tuesday, July 15, 2014 7:19 PM
  • User1336021323 posted

    In case of a varchar or text column

    select isnull(columnname,'') as columnname from tablename

    In case of an integer

    select isnull(columnname,0) as columnname from tablename

    Thanks

    Ritesh

    Tuesday, July 15, 2014 11:44 PM