Is there a simpler T-SQL construct for "all of these columns to be equal (NULLs ignored) on a row" - effective I want to say:
WHERE MIN(a, b, c) = MAX(a, b, c) OR COALESCE(a, b, c) IS NULL
- this would be the equivalent of the COALESCEs of all the permutations to be equal - but there is no non-aggregating MIN/MAX function
An alternative for 3 columns is:
WHERE (
COALESCE(a, b, c) = COALESCE(b, c, a)
AND COALESCE(a, b, c) = COALESCE(c, a, b)
AND COALESCE(a, b, c) = COALESCE(b, a, c)
AND COALESCE(a, b, c) = COALESCE(a, c, b)
AND COALESCE(a, b, c) = COALESCE(c, b, a)
)
OR COALESCE(a, b, c) IS NULL
i.e. "All non-NULL columns a, b, c must be equal or all columns may be null"
Obviously a PIVOT/UNPIVOT implementation could be done or a complex CASE statement, but I'm looking for something relatively simple.
In this case, the columns are all integers, so I guess there is probably a math trick I could figure out.