This might not make any sense, but what i’m trying to do is select a column based on when another column is least. For example, I have 3 int columns and 3 varchar columns
In the below example Unit = int, and Link = varchar
Unit1|Link1|Unit2|Link2|Unit3|Link3 72|www.google.com|43|www.yahoo.com|9212|www.lycos.com
In the above example Unit2 is least so I’d want to select Link2.
This is how i’m selecting least, so any help would be awesome
select Least(
Coalesce(myTable.Unit1,
myTable.Unit2,
myTable.Unit3),
Coalesce(myTable.Unit1,
myTable.Unit2,
myTable.Unit3),
Coalesce(myTable.Unit1,
myTable.Unit2,
myTable.Unit3))
AS LowestUnit
from myTable
One approach:
(You could use an ELSE Link3 in place of that third WHEN for an equivalent result, I just went with checking all three, and letting the ELSE default to NULL.)
Equivalent and more terse: