No, you can reduce it to 2 calls, as shown below. But no matter what you do, it will be more expensive than it really is, since you do it very quickly. You can think of something to improve when you really have heavy operations. It is just nothing. You can also make the get_min function, but again I donβt think it is worth it.
With two calls:
case when table3.col3 then table3.col4 when (FLOOR(table3.col3/0.2)*0.2) > 20 THEN 20 else FLOOR(table3.col3/0.2)*0.2 end
With min function:
case when table3.col3 then table3.col4 else dbo.get_min(FLOOR(table3.col3/0.2)*0.2,20) end
As a side note, the min function should be built, which I mean (user-defined function).
source share