Some nested CASE blocks, e.g.:
CASE
WHEN (condition1)
THEN
CASE
WHEN (condition2)
THEN result1
ELSE result2
END
ELSE result2
END
can be optimized to:
CASE
WHEN condition1 AND condition2
THEN result1
ELSE result2
END
In practice we get those kinds of chained CASE blocks in the following scenarios:
context.Set<Product>().OrderBy(p => p.UnitsInStock > 10 ? p.ProductID > 40 : p.ProductID <= 40)
Some nested CASE blocks, e.g.:
CASE WHEN (condition1) THEN CASE WHEN (condition2) THEN result1 ELSE result2 END ELSE result2 ENDcan be optimized to:
CASE WHEN condition1 AND condition2 THEN result1 ELSE result2 ENDIn practice we get those kinds of chained CASE blocks in the following scenarios: