Published on

Integer Division Result in Decimal in SQL server

Authors

Problem

Get the result in Decimal value by dividing Integer values in SQL Server.

Ex:

SELECT 5/2
--Actual 2
--Expected 2.5

Resolution

Convert to decimal

SELECT CONVERT(decimal(4,2), 5) /2
--2.500000

Multiplying by 1.0 Converts value into numeric

SELECT 5*1.0/2
--2.500000

Shorthand method *1.

SELECT 5*1./2
--2.500000