I have been trying a query to select the minimum value in a row but also exclude a certain value (-998).
The table looks like this:
col1 col2 col3
----------------------------------
1 1 -998
2 -998 2
3 2 1
-998 1 3
So in the first row, the minimum value would be 1; in the second row, it would be 2; and in the third row, it would be 1 again.
I tried using a case statement and excluding -998 in each condition, but it keeps grabbing -998 for some reason.
SELECT
CASE
WHERE (col1 <= col2 and col1 <= col3) and col1 != -998 THEN col1
WHERE (col2 <= col1 and col2 <= col3) and col2 != -998 THEN col2
WHERE (col3 <= col1 and col3 <= col2) and col3 != -998 THEN col3
END AS [MIN_VAL]
FROM myTable
If anyone can point me in the right direction that would ge awesome.