SQLTeam.com | Weblogs | Forums

Dividing and Rounding up not working

sql2008

#1

Hi

I am having problem with not being able to divide and round up without the quantity showing as 0.

The dividing quantity should be 0.9425 and roundup to 1.

What am I doing wrong?

declare @replenishmentQty int
declare @handlingQty int
declare @totalQty int
declare @totalQty2 int

set @replenishmentQty = 1920 - 35
set @handlingQty = 2000

set @totalQty = CONVERT(FLOAT,@replenishmentQty) / @handlingQty
set @totalQty2 = CAST(@replenishmentQty as float) / @handlingQty

select @totalQty
select @totalQty2


#2

You should use the round function

set @totalQty = round(1.0*@replenishmentQty/@handlingQty,0)

#3

Thanks very much for the quick response. This seems to work.