locked
ISNULL query RRS feed

  • Question

  • User-504128882 posted

    Hi,

    ISNULL(column,0) means that if field is null replace it with 0.

    What does the query Isnull(column,0)=3 means.

    Saturday, November 28, 2015 7:41 AM

Answers

  • User1644755831 posted

    Hello JiJish,

    I suspect that Isnull(column,0)=3 is in where clause. and its checking the condition in many cases its done because = does not work with NULL I mean you can not write a statement like column = null you have to write column is null. in most cases you are supposed to pass a variable in the query for example.

    declare @param int = null 
    
    -- this simplifies things and you don't have to write to cases. 
    select * from table where isnull(column,0) = isnull(@param,0)
    
    --other case is 
    select * from table where (column = @param) OR (column is null and @param is null)

    --this both returns the same results

    With Regards,

    Krunal Parekh

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 29, 2015 1:39 AM
  • User364663285 posted

    Hi,

    ISNULL(column,0) means that if field is null replace it with 0.

    What does the query Isnull(column,0)=3 means.

    It does check whether is the column does equal 3 or not, even when the column is null.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 29, 2015 12:52 PM
  • User-62323503 posted

    In this case, Isnull(column,0)=3 or column =3 is same. It would give the same result.

    Isnull(column,0)=3

    In this case, if the value is null you are changing it to 0 and 0<>3 so it would return false

    column =3

    In this case, if the value is null in column it would still return false as null can not be compared with =

    if the value in isnull and right side value are same like below, then it would make difference 

    Isnull(column,0)=0 or Isnull(column,3)=3

    Here, if value of column is null then the value of left side will be equal to right side and will return true

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 30, 2015 3:45 AM

All replies

  • User753101303 posted

    Hi,

    It just compares likely this result with 3 !? Isn't it in a where clause?

    Saturday, November 28, 2015 9:19 AM
  • User1644755831 posted

    Hello JiJish,

    I suspect that Isnull(column,0)=3 is in where clause. and its checking the condition in many cases its done because = does not work with NULL I mean you can not write a statement like column = null you have to write column is null. in most cases you are supposed to pass a variable in the query for example.

    declare @param int = null 
    
    -- this simplifies things and you don't have to write to cases. 
    select * from table where isnull(column,0) = isnull(@param,0)
    
    --other case is 
    select * from table where (column = @param) OR (column is null and @param is null)

    --this both returns the same results

    With Regards,

    Krunal Parekh

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 29, 2015 1:39 AM
  • User364663285 posted

    Hi,

    ISNULL(column,0) means that if field is null replace it with 0.

    What does the query Isnull(column,0)=3 means.

    It does check whether is the column does equal 3 or not, even when the column is null.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 29, 2015 12:52 PM
  • User-62323503 posted

    In this case, Isnull(column,0)=3 or column =3 is same. It would give the same result.

    Isnull(column,0)=3

    In this case, if the value is null you are changing it to 0 and 0<>3 so it would return false

    column =3

    In this case, if the value is null in column it would still return false as null can not be compared with =

    if the value in isnull and right side value are same like below, then it would make difference 

    Isnull(column,0)=0 or Isnull(column,3)=3

    Here, if value of column is null then the value of left side will be equal to right side and will return true

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 30, 2015 3:45 AM