Wednesday 21 March 2012

MS SQL 2012 - How to Convert Integer to Decimal




If I try to divide 1/2 in MS SQL I will get 0
For instance the following statement will produce 0
Select 1/2



To fix it just convert both 1 and 2 to decimals
SELECT CONVERT(decimal(5,2),1) / CONVERT(decimal(5,2),2)
which will produce correct result (0.5)







No comments:

Post a Comment