I have 2 nullable CHAR
columns and I need to check if only one of them is null.
Doing
(a IS NULL AND b IS NOT NULL) OR (a IS NOT NULL AND b IS NULL)
is boring. And I would like to avoid creating custom functions for that.
I was thinking about something like
COALESCE(a, 1) + COALESCE(b, 1) = 1
but as long as a
is char
- it causes operand type error.
So, any tricky solutions?
COALESCE(a,b)=COALESCE(b,a)
:) Will yield incorrect value ifa=b
. sqlfiddle.com/#!1/9c33b/1 – mellamokb Apr 18 '12 at 3:31select coalesce(null, null) = coalesce(null, null)
returns not boolean (which could lead to errors in some cases) – zerkms Apr 18 '12 at 3:36