DECLARE @decimal DECIMAL (19,2) = 100;
DECLARE @integer INT = 100;
SELECT @decimal / 3,
@integer / 3,
@integer / 3.0,
CAST( @integer / 3.0 AS DECIMAL(19, 2) );
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
Open in new window
What you are experiencing is 'integer division', where T-SQL will interpret the division of two integers as a result that is also an integer, hence 5 / 2 = 2 and not 2.5.To avoid this, you need to CAST either the numerator or the denominator as a decimal, and not the entire result.