|
-
Apr 17th, 2012, 12:53 PM
#1
Thread Starter
Member
[RESOLVED] IF within select statement
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|