In my @disttable for some columns result is showing as null. Instead, I want to show 0. I want to show 'O' in Pivot table in place of NULL. I tried to give isnull for Total..But it did not work properly.
declare @DistTable Table
(
Party nvarchar(200),
DistName nvarchar(200),
Total int,
TotalSeats int,
DeclaredSeats int
)
insert into @DistTable
SELECT C.English AS Party,f.English as DistNAME,count(C.English) as Total,
TOTALSEATS=(SELECT COUNT(*) FROM TBL_CONSTITUENCYMASTER c WHERE c.Phase= 3 and c.StateCode=29 and c.reg_code = 61),
DECLAREDSEATs=(SELECT COUNT(*) FROM TBL_CONSTITUENCYMASTER c WHERE c.Phase= 3 and c.StateCode=29 and c.reg_code = 61 and Lead_WonCode=100)
FROM TBL_CONSTITUENCYMASTER A
LEFT OUTER JOIN tbl_CandidateMaster B ON A.Lead_CandiCode = B.Cand_Code
LEFT OUTER JOIN tbl_AllianceMaster C ON B.AllianceCode = C.AllianceCode
join tbl_regionmaster f on a.reg_code=f.reg_code
join tbl_olddistrictMaster e on a.Old_dist_code=e.old_dist_code
join tbl_DistrictMaster D on A.Dist_Code=D.Dist_Code WHERE A.STATECODE = 29 and A.Phase = 3 and A.Lead_WonCode = 100 and f.reg_code = 61 group by c.English,f.English order by F.English
select * from @DistTable pivot (min(Total) for Party in([TRS],[INC],[TDP],[BJP],[CPI],[CPM],[OTH])) as t
The result is
ADILABAD 163 163 67 27 NULL NULL NULL NULL 69
Instead of NULL how do I show 0
in result of a pivot table in SQL SERVER?