
/****** Object:  View [dbo].[ApiPP_Info]    Script Date: 13.09.2021 15:19:34 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE VIEW [dbo].[ApiPP_Info] as
SELECT 
		pp.*, ps.SumQuant
  FROM [dbo].ApiProdActivities pp
  JOIN 
  (select OperationId, Max(Id) MaxId, Sum(pp2.Quantity) SumQuant  from dbo.ApiProdActivities pp2  where pp2.Confirmed= 1 GROUP BY pp2.OperationId ) ps ON ps.OperationId = pp.OperationId and pp.Id = ps.MaxId
  where pp.Confirmed= 1

GO


