ISNULL and COALESCE. They Both Do the Same Thing... Right?
I thought they both replace NULLs. So, what's the big deal? They're the same.
But one day, one worked, and the other didn't.
Using ISNULL, the result became int, and our report expecting decimal broke quietly or rounded numbers incorrectly.
Lesson:
Use COALESCE when data types may vary.
Small SQL details can break big reports
They look the same. But under the hood, details matter.
If you know the square of a number, suppose 𝟐𝟎² = 𝟒𝟎𝟎,
then you can get the square of the next number i.e. of 𝟐𝟏, by adding the sum of these two numbers:
𝟒𝟎𝟎 + (𝟐𝟎) + (𝟐𝟏) = 𝟒𝟒𝟏.
SELECT * FROM orders WHERE YEAR(order_date) = 2025;
SELECT * FROM orders WHERE order_date >= '2025-01-01' AND order_date < '2026-01-01';
Which query is faster?