Hi,
I have created one store proc to retrieve details from one table with multiple where conditions. But now the problem is I am having the null values, I want to remove it, Kindly help me.
This is what it looks now:
Outlet TodayFBREv CMMTDRev CMYTDRev
1 NULL NULL 200
1 NULL 100 NULL
1 100 NULL NULL
2 NULL NULL 300
2 NULL 200 NULL
2 50 NULL NULL
What i want it to look:
Outlet TodayFBREv CMMTDRev CMYTDRev
1 100 100 200
2 50 200 300
This is my code Store proc :
Declare @FBTable TABLE (Outlet nvarchar(max), TodayFBRev money, CMMTDFBRev money, CMYTDFBRev money)SET NOCOUNT ON;
INSERT INTO @FBTable
Select Outlet,Sum(case when Revenue = 'Beverage' then TotalAmount else 0 end) + SUM(case when Revenue = 'Food' then TotalAmount else 0 end) as TodayFBRev, NULL, NULL
From FBRevenueByOutlet
Where Date = @date
Group BY Outlet
UNION
Select Outlet, NULL, Sum(case when Revenue = 'Beverage' then TotalAmount else 0 end) + SUM(case when Revenue = 'Food' then TotalAmount else 0 end) as CMMTDFBRev, NULL
From FBRevenueByOutlet
Where (Date BETWEEN @CurStartMonth AND @date)
Group BY Outlet
UNION
Select Outlet, NULL, NULL, Sum(case when Revenue = 'Beverage' then TotalAmount else 0 end) + SUM(case when Revenue = 'Food' then TotalAmount else 0 end) as CMYTDFBRev
From FBRevenueByOutlet
Where (Date BETWEEN @CurStartYear AND @date)
Group BY Outlet
Select * From @FBTable Where TodayFBRev IS NOT NULL
Union
Select * From @FBTable Where CMMTDFBRev IS NOT NULL
Union
Select * From @FBTable Where CMYTDFBRev IS NOT NULL