Es nulo > 0 (entero) [duplicado]

If I have in my sql something like that:

SELECT * 
FROM SOMETABLE 
WHERE ((SELECT ONECOLUMN FROM ANOTHERTABLE WHERE ID = 42) > 0)

If I got a NULL in ONECOLUMN it will be greater then 0?

preguntado el 28 de mayo de 14 a las 13:05

This is something you can try on your own. -

5 Respuestas

As NULL means "not known", NULL is not greater than 0. It's not smaller either. It's not known. Hence NULL > 0 results in NULL, rather than in TRUE or FALSE.

contestado el 28 de mayo de 14 a las 14:05

NULL is not greater than zero. NULL is not equal to zero. NULL is not less than zero.

Any given integer you might choose would meet exactly one of these three conditions. But not NULL.

NULL isn't an integer. It's a marker indicating that a value is not present. This could mean that a value exists, but is unknown. It could also indicate that no value exists in this context.

You can use the ISNULL function to find out whether a NULL is present instead of a value. But if you compare a value with zero, and there is a NULL in place of the value, you won't get either TRUE or FALSE as a result.

If you are confused, you're in good company.

contestado el 28 de mayo de 14 a las 13:05

¿Qué tal comprobar NULL y luego regresando 0 if true otherwise return the value of ONECOLUMN:

SELECT * 
FROM SOMETABLE 
WHERE (
  SELECT CASE WHEN ISNULL(ONECOLUMN) THEN 0 ELSE ONECOLUMN END 
  FROM ANOTHERTABLE 
  WHERE ID = 42
) > 0

contestado el 28 de mayo de 14 a las 13:05

Null is unknown and it cannot be compared to any value. It cannot be greater or lesser.

contestado el 28 de mayo de 14 a las 13:05

SELECT *
    FROM SOMETABLE
    WHERE (
        IsNull((SELECT ONECOLUMN
            FROM ANOTHERTABLE
            WHERE ID = 42), IntValue) > 0
          )

If you need to accept the Null so IntValue puede ser 1 de otra manera -1 está bien

contestado el 28 de mayo de 14 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.