The following query works great outside of it is still returning null values as NULL
instead of 0
. Specifically, this is summing up the amount of times something has happened in a specified date range. If the value just doesn't exist within the parameters (i.e. NULL
,) then for readability sake I would like for it to return a 0 (the table, which is a join of multiple temp tables, only contains integers.) I have researched and found this case " How can I change NULL to 0 when getting a single value from a SQL function? " and have tried all of the suggestions there, including COALESCE
.
(SELECT tn.teamtext, tn.teamid, ISNULL(sum(ISNULL(case when CONVERT(smalldatetime,ca.dModLast,101) BETWEEN '2012-03-01' AND '2012-03-10' then 1 else 0 end, 0)), 0) AS cnt3
FROM teamnames AS tn
LEFT OUTER JOIN caseaudit AS ca
ON tn.teamID = ca.referteamID2
WHERE ca.referteamid1 <> ca.referteamid2 AND ca.isactive = 1 AND ca.groupid = 18 AND ca.accountid = 2 AND ca.referteamid1 = 31 AND ca.auditnote <> 'Suspend Case'
GROUP BY tn.teamtext, tn.teamid) AS c
To give an idea of the returned table I am looking at, here it is:
4H BOSS 55 59 3
4H BSG 0 3 2
4H SALES AND MKTG 0 0 0
ACCOUNTS RECEIVABLE 0 0 0
ASSET MANAGEMENT 9 16 0
AUDIT 0 0 NULL
BOSS 4 5 0
CORPORATE BSG 0 7 5
CUSTOMER SUPPORT 87 133 NULL
NETWORK ENGINEERING 11 15 0
PRODUCTION ENGINEERING 116 142 5
PRODUCTION OPERATIONS 0 1 0
SECURITY 2 6 3
SNFAL PRODUCT TEAM 0 14 11
VOICE SERVICES 18 21 0
XEROX 4 8 0