Skip to content
Advertisement

How to compare two columns in the CASE statement

I have two columns Speed_A and Speed_B. Now I will compare both columns and will select the higher one in a new table. Something like this:

How does it work?

Advertisement

Answer

Assuming your speeds are numerically typed you might get this as easy as:

Your ELSE will only occur, when A and B are equal, In this case it doesn’t matter, which one you return.

UPDATE

column´s data type is integer. And yes there are nulls

If A is null return B, If b is null return A (works for A and B is null implicitly). Otherwise both are not null and therefore the statement above should be perfect

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement