Tuesday, May 8, 2012

Capping negative numbers to zero

select 
   ( col1 + abs(col1) ) / 2 as capped_to_zero
from tbl

is faster than:


select 
   case when col1 >= 0 then col1 else 0 end as capped_to_zero
from tbl


No comments:

Post a Comment