There is no SET-based approach since SQL is intended to be aggregated by row rather than column-wise.
I would really expect CASE to be pretty fast here ...
CASE WHEN Q4 <> 0 THEN Q4
WHEN Q3 <> 0 THEN Q3
WHEN Q2 <> 0 THEN Q2
WHEN Q1 <> 0 THEN Q1
ELSE NULL
END
There is, however, an alternative using NULL and COALESCE ...
COALESCE(NULLIF(Q4, 0), NULLIF(Q3, 0), NULLIF(Q2, 0), NULLIF(Q1, 0))
source
share