Dividing 2 numbers in Sql Server

前端 未结 4 1047
一向
一向 2021-01-06 03:11

I am doing SQL Server query calculations and the division always gives me zero.

SUM(sl.LINES_ORDERED) 
, SUM(sl.LINES_CONFIRMED)
, SUM(sl.LINES_CONFIRMED) /          


        
4条回答
  •  一整个雨季
    2021-01-06 03:52

    It will be because you're divinding two integers.

    Convert the two values in the division to decimals first:

    , SUM(convert(decimal(12,2),sl.LINES_CONFIRMED)) 
    / SUM(convert(decimal(12,2),sl.LINES_ORDERED)) AS 'Percent'
    

提交回复
热议问题