SqlReports

+

4/2/2020 3:47:24 PM

Changes

Details

diff --git a/TotalRevenueByCategories.sql b/TotalRevenueByCategories.sql
index 7e8194f..bef5f7c 100644
--- a/TotalRevenueByCategories.sql
+++ b/TotalRevenueByCategories.sql
@@ -113,7 +113,8 @@ begin
 	
 	declare @ShopsCount table (
 			CompanyID int, 
-			ShopsCount int 
+			ShopsCount int,
+			CoffeeShopsCount int
 			
 			INDEX IX_ShopsCount_CompanyID NONCLUSTERED (CompanyID)
 		)
@@ -121,7 +122,14 @@ begin
 	insert into @ShopsCount
 		select
 			t.CompanyID,
-			Sum(1) as ShopsCount 		
+			Sum(1) as ShopsCount, 		
+			
+			Sum	(
+					case
+						when (isnull(pg.Flags, 0) & 1) <> 0 then 1
+						else 0
+					end
+				) as CoffeeShopsCount
 
 		from (
 				select
@@ -134,6 +142,9 @@ begin
 					sl.ShopID
 
 			) as t
+			
+			inner join dbo.Shops s with (nolock) on s.Id = t.ShopID
+			left join dbo.Planograms pg with (nolock) on pg.Id = s.PlanogramId
 		
 		group by
 			t.CompanyID		 
@@ -255,6 +266,7 @@ begin
 		@DateTo as DateTo,
 		c.Name,
 		isnull(sc.ShopsCount, 0 ) as ShopsCount,
+		isnull(sc.CoffeeShopsCount, 0) as CoffeeShopsCount,
 		isnull(totals.SalesCount, 0) as SalesCount,
 		isnull(scbc.CategoryCount01, 0) as CategoryCount01,
 		isnull(scbc.CategoryCount02, 0) as CategoryCount02,