Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Review
So you think you can count?
Rounding functions and more
Review and practice

Instruction

Wait… what? We got a 0? After all these years of being taught it's 0.25?

Has someone deceived us? Not really.

What happened here is called integer division. Integer division occurs when both the dividend and the divisor are integers. Since they are integers, SQL Server wants to return an integer result to match the operand types. In other words, it brutally cuts off the decimal part, which is .25 in our case. The zero (0) is the only thing left.

So, how can we make sure that the result includes the decimal part? One way is to change the type of one of the values to a decimal (e.g., 1 / 4.0 instead of 1 / 4). In this course, we will always change the type of the counter.

Exercise

Run another example query to see what happens when you use a decimal.