I have a SQL select statement that calculates the value of one of the elements being returned by the select. Following is that SQL.
, AVGManual =
(select count(*)
from CustomerFeedback as AV
where av.SellingArea <> 'Find Merchandise'
and av.Store = cf.Store
)
/ (select count(distinct(tl.associatenumber))
from CustomerFeedback as tl
where tl.SellingArea <> 'Find Merchandise'
and tl.Store = cf.Store
)

----------------------------------------------------------------------------------
The problem is that the divisor is a zero in some cases and gets an error.
I tried writing an IF statement but it is giving me all kinds of errors. See
below:
, if (select count(distinct(tl.associatenumber))
from CustomerFeedback as tl
where tl.SellingArea <> 'Find Merchandise'
and tl.Store = cf.Store) > 0
BEGIN
AVGManual =
(select count(*)
from CustomerFeedback as AV
where av.SellingArea <> 'F M'
and av.Store = cf.Store
)
/ (select count(distinct(tl.associatenumber))
from CustomerFeedback as tl
where tl.SellingArea <> 'F M'
and tl.Store = cf.Store
)
END
ELSE
AVGManual = 0

, PCTTTL = 22

------------------------------------------------------------------------------------
I want AVGManual to be 0 or a calculated value.