Click here to Skip to main content
16,018,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a SQLQuery in my C#Application
SQL
select sum(deductions) from Billing


Its working perfectly when values are there.
But when deduction column contains NULL values then I want that it should return zero(0).

Please help me.
Posted
Comments
[no name] 29-Aug-12 15:12pm    
Thanks TR,OriginalGriff,Prashant i solved my problem
I accept all three answers.
and +5 too.

Hi Try this.
select isnull(SUM(deductions),0) from Billing
 
Share this answer
 
v4
Comments
Kuthuparakkal 29-Aug-12 5:31am    
unnecessary overload, voting down
Sachin Gargava 29-Aug-12 5:43am    
how you can say overload can u please explain me ?
[no name] 29-Aug-12 15:12pm    
Kuthuparakkal is correct.
Me too didn't take this overhead.
its a long query.
Hey use below code:
SQL
select isnull(SUM(deductions),0) from Billing
 
Share this answer
 
Comments
_Amy 29-Aug-12 4:41am    
If any row contains null values then the output of this query will be null.
[no name] 29-Aug-12 15:10pm    
its worked for me.
Try:
SQL
SELECT SUM(ISNULL(deductions, 0)) FROM Billing
 
Share this answer
 
Comments
__TR__ 29-Aug-12 4:30am    
+5 :)
Kuthuparakkal 29-Aug-12 6:36am    
5+
[no name] 29-Aug-12 15:10pm    
its worked for me thanks
Try ISNULL function[^]

SQL
select sum(ISNULL(deductions,0)) from Billing
 
Share this answer
 
Comments
Kuthuparakkal 29-Aug-12 6:36am    
5+
__TR__ 29-Aug-12 6:56am    
Thanks.
[no name] 29-Aug-12 15:11pm    
thanks
its worked for me.
+5
__TR__ 29-Aug-12 15:36pm    
You are welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900