The queries identify the number of unique transactions and the number of lines in the table. Dividing one by the other will reveal the average lines per transaction.
This query reveals the Number of Sales Transactions processed on a given day and the number of overall lines.
DECLARE @Date as DATETIME
SET @Date = '04/12/2017'
/*Sales Orders*/
select sum(a.Sales_Orders) Sales_Orders from
(Select count(s.Sales_Orders)
Sales_Orders from
(Select COUNT(sl.SOPNUMBE)
Sales_Orders from SOP10100 SH
Inner Join SOP10200
SL
on SH.SOPNUMBE = SL.SOPNUMBE
and SH.SOPTYPE = SL.SOPTYPE
where sh.DOCDATE = @Date
group by SL.SOPNUMBE) S
Union All
Select count(s.Sales_Orders) Sales_Orders
from (Select COUNT(sl.SOPNUMBE) Sales_Orders from
SOP30200 SH
Inner Join SOP30300
SL
on SH.SOPNUMBE = SL.SOPNUMBE
and SH.SOPTYPE = SL.SOPTYPE
where sh.DOCDATE = @Date
group by SL.SOPNUMBE) S) a
/*Sales Lines*/
select sum(a.SOP_Lines) SOP_Lines from
(Select COUNT(SH.SOPNUMBE) SOP_Lines from SOP10100 SH
Inner Join SOP10200
SL
on SH.SOPNUMBE = SL.SOPNUMBE
and SH.SOPTYPE = SL.SOPTYPE
where sh.DOCDATE = @Date
Union All
Select COUNT(SH.SOPNUMBE) SOP_Lines from
SOP30200 SH
Inner Join SOP30300
SL
on SH.SOPNUMBE = SL.SOPNUMBE
and SH.SOPTYPE = SL.SOPTYPE
where sh.DOCDATE = @Date) a
No comments:
Post a Comment