Reduce Redundancy Of CASE Expresion SQL Server

45 Views Asked by At

Here is my SQL Server query

SELECT
CASE(
    SELECT POPULATION
    FROM MEXICO
) WHEN 0 THEN 1 ELSE
    SELECT POPULATION
    FROM MEXICO
END

I need to make a query return 1 if it's value is equal to 0, is there a way to do it without repeating the SELECT?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes there is:

select case population
         when 0 then 1
         else population
       end
from mexico;

Fiddle