Click here to Skip to main content
15,899,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I give the following coding for get datas from two tables
SQL
 select distinct
(T1.Billno),T1.Billdate,T1.CCode,T1.CName,T1.Nettot as TotalAmount,
(select sum(T2.Paid) 
FROM Pending T2 
WHERE 
T1.Billno=T2.Billno) as Paid,
T1.Nettot-(select sum(T2.Paid) 
FROM Pending T2 
WHERE T1.Billno=T2.Billno) as Balance
FROM Billing1 T1 where T1.Cname='WelForge'

I get the correct answer

But if there are no datas in T2 Table the column is displayed empty
so the next column is also displays with empty. so i want to display with 0 when there are no records in second table how to do it please help anybody

Thank you
Posted
Updated 11-Jan-12 20:29pm
v4

1 solution

Try this

SQL
select distinct(T1.Billno),T1.Billdate,T1.CCode,T1.CName,T1.Nettot as TotalAmount,
 COALESCE(sum(T2.Paid),0) as Paid
,T1.Nettot- COALESCE(sum(T2.Paid),0)  as Balance
from Billing1 T1
Left Outer Join Pending T2 On T1.Billno=T2.Billno
where T1.Cname='WelForge
 
Share this answer
 
Comments
devausha 12-Jan-12 2:47am    
Thank you very much

Very Nice

Thanks alot
RDBurmon 12-Jan-12 2:52am    
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