Replace CASE WHEN statement with something more sensible While checking my SPs today I found that I have,

SELECT  COUNT(*)
,CASE WHEN ISNULL(MIN(COALESCE(MP.NewPrice, MP.Price, 2147483647)),0) = 2147483647 THEN 0 ELSE ISNULL(MIN(COALESCE(MP.NewPrice, MP.Price, 2147483647)), 0) END
FROM    MerchantsProducts MP


I need to replace this with something which make more sense. Can someone please review this?
COALESCE(…, …, 2147483647) will never return NULL.  Furthermore, MIN(…) will only return NULL when all of its inputs are NULL.

Assuming that every NewPrice and every Price is at most 2147483647, the following query should be equivalent.

SELECT COUNT(*)
     , ISNULL(MIN(COALESCE(NewPrice, Price)), 0)
    FROM MerchantsProducts