find MIN, MAX of multiple rows from multiple columns
965732Oct 9 2012 — edited Oct 10 2012Hello,
I need to figure out how to pull the MIN/MAX of multiple rows from multiple columns into one column. Even if some are NULL/blank.
For Example: (C: Column, R: Row, N - NULL/Blank)
C:____1____2____3____ 4____Max
R:____20___22___13____4____*22*
R:____N____N____32____14___*32*
R:____N____12____N____N____*12*
That is, it always gives a value for MIN/MAX unless there are NO values in all the rows of the columns.
So if there is one value, it will select that for the MIN/MAX, as it's the smallest/biggest since there is nothing to compare it to.
Here is my current code:
CASE WHEN COLUMN 1 < COLUMN 2 THEN COLUMN 2 ELSE COLUMN 1 END