Dividing 2 numbers returns 0
问题 I'm trying to divide 2 counts in order to return a percentage. The following query is returning 0 : select ( (select COUNT(*) from saxref..AuthCycle where endOfUse is null and addDate >= '1/1/2014') / (select COUNT(*) from saxref..AuthCycle where addDate >= '1/1/2014') ) as Percentage Should I be applying a cast? 回答1: I would do it differently, using two sum s: select sum ( case when endOfUse is null and addDate >= '1/1/2014' then 1 else 0 end ) * 100.0 -- if you want the usual 0..100 range