With the help of this query i was unable to show null rows when date was changed.
please help me
select p.partnerid,
sum(case when c.amount is not null then c.amount else 0 end) as amount,
sum(case when c.netamt is not null then c.netamt else 0 end) as netamt,
sum(case when c.netamt - c.amount is not null then c.netamt - c.amount else 0 end) as interest,
sum(case when c.installment = 20 then c.amount else 0 end) as Twenty,
sum(case when c.installment = 10 then c.amount else 0 end) as Ten,
sum(case when c.installment = 5 then c.amount else 0 end) as Five,
sum(case when c.installment = 2 then c.amount else 0 end) as Two
from partnerinfo p left outer join customerinfo c on p.partnerid = c.partnerid
where (c.startdate is null OR (c.startdate >= '2012-3-15' and c.startdate <= '2012-12-30'))
and (c.partnerid is null or c.partnerid) and p.manager = 1
group by p.partnerid
For better understanding here are the images
1. http://i46.tinypic.com/155l4cp.jpg
2. http://i49.tinypic.com/357ki3b.jpg
Loading
Santhosh Kumar JayaramanPosted Jun 21, 2012, 1:00 AM
select p.partnerid,
sum(case when c.amount is not null then c.amount else 0 end) as amount,
sum(case when c.netamt is not null then c.netamt else 0 end) as netamt,
sum(case when c.netamt - c.amount is not null then c.netamt - c.amount else 0 end) as interest,
sum(case when c.installment = 20 then c.amount else 0 end) as Twenty,
sum(case when c.installment = 10 then c.amount else 0 end) as Ten,
sum(case when c.installment = 5 then c.amount else 0 end) as Five,
sum(case when c.installment = 2 then c.amount else 0 end) as Two
from partnerinfo p left outer join customerinfo c on p.partnerid = c.partnerid
where (c.startdate is null OR (c.startdate >= '2012-3-15' and c.startdate <= '2012-12-30'))
and (c.partnerid is null or c.partnerid) and p.manager = 1
group by p.partnerid
unionall
select p.partnerid,
0,
0,
0,
0,
0,
0,
0
from partnerinfo p left outer join customerinfo c on p.partnerid = c.partnerid
where (c.startdate is null OR (c.startdate >= '2011-3-15' and c.startdate <= '2012-3-15'))
and (c.partnerid is null or c.partnerid) and p.manager = 1
group by p.partnerid
vara reddyPosted Jun 21, 2012, 12:45 AM
But i had a problem with count.
when placed like below 1,145 are getting 0 but 12,14, 24 they are showing previous count
count((c.startdate>= '2012-3-15' and c.startdate <= '2012-12-30')) as accounts,
any way to change?????
Santhosh Kumar JayaramanPosted Jun 21, 2012, 12:31 AM
You have to remove the condition in where clause and set it in select clause.
For eg,
select p.partnerid,
sum(case when c.amount is not null and (c.startdate>= '2012-3-15' and c.startdate <= '2012-12-30') then c.amount else 0 end) as amount,
The syntax might not be correct, but this is the idea