SqlReports
Changes
GetAverageCheck.sql 30(+25 -5)
Details
GetAverageCheck.sql 30(+25 -5)
diff --git a/GetAverageCheck.sql b/GetAverageCheck.sql
index b7161ad..634e64f 100644
--- a/GetAverageCheck.sql
+++ b/GetAverageCheck.sql
@@ -42,7 +42,7 @@ begin
set @DateTo = dateadd(ms, -2, dateadd(day, 1, @DateTo_Date))
- declare @t1 table (ShopID int index IX_t1_ShopID, Total decimal(15,2), ItemsCount int, CashCredit int, BankcardCredit int, MobileAppCredit int, CardNumber nvarchar(max))
+ declare @t1 table (ShopID int index IX_t1_ShopID, Total decimal(15,2), ItemsCount int, CashCredit int, BankcardCredit int, MobileAppCredit int, ObedRuCredit int, CardNumber nvarchar(max))
insert into @t1
select
@@ -52,6 +52,7 @@ begin
ss.CashCredit,
ss.BankcardCredit,
ss.MobileAppCredit,
+ sc.Value as ObedRuCredit,
c.CardNumber
from dbo.Shops sh with (nolock)
@@ -66,6 +67,11 @@ begin
sl.TerminalId = t.Id
and sl.SessionId = ss.SessionId
+ left join dbo.SessionCredits sc with (nolock) on
+ sc.TerminalId = t.Id
+ and sc.SessionId = ss.SessionId
+ and sc.Type = 5 -- ObedRu
+
left join dbo.Cards c on c.Id = ss.CardId
@@ -80,6 +86,7 @@ begin
ss.CashCredit,
ss.BankcardCredit,
ss.MobileAppCredit,
+ sc.Value,
c.CardNumber
set @t1_RowCount = (select count(*) from @t1)
@@ -94,7 +101,8 @@ begin
t.Guests,
t.ByCashCount,
t.ByBankcardCount,
- t.ByMobileAppCount
+ t.ByMobileAppCount,
+ t.ByObedRuCount
from (
select
@@ -138,8 +146,14 @@ begin
when t1.MobileAppCredit > 0 then 1
else 0
end
- ) as ByMobileAppCount
+ ) as ByMobileAppCount,
+ Sum (
+ case
+ when t1.ObedRuCredit > 0 then 1
+ else 0
+ end
+ ) as ByObedRuCount
from @t1 t1
@@ -193,8 +207,14 @@ begin
when t1.MobileAppCredit > 0 then 1
else 0
end
- ) as ByMobileAppCount
-
+ ) as ByMobileAppCount,
+
+ Sum (
+ case
+ when t1.ObedRuCredit > 0 then 1
+ else 0
+ end
+ ) as ByObedRuCount
from @t1 t1
end
\ No newline at end of file