You also need to group by "NPACode > 0"
The easiest way should be:
SELECT brcode
,count(Acno)
,sum(balance) AS Outstanding
,CASE
WHEN NPACode > 0
THEN sum(balance)
ELSE 0
END AS NPA
FROM #temploan
GROUP BY BrCode
,CASE WHEN NPACode > 0 THEN 1 ELSE 0 END
ORDER BY BrCode
<edit>
I'm wondering about the purpose of Outstanding vs NPA, they would be the same if NPACode is > 0
I have a feeling this is what you want:
SELECT brcode
,count(Acno)
,sum(balance) AS Outstanding
,SUM(
CASE
WHEN NPACode > 0
THEN balance
ELSE 0
END
) AS NPA
FROM #temploan
GROUP BY BrCode
ORDER BY BrCode
</edit>