
/****** Object:  UserDefinedFunction [dbo].[apiWmsLineSumQuantAbove]    Script Date: 07.09.2021 13:45:30 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[apiWmsLineSumQuantAbove]
(
	@WmsLine int
	
)
RETURNS  decimal(18,4)
BEGIN
   DECLARE @res decimal(18,4);
 set @res = ISNULL((
	select SUM (powyzej.Quantity) from dbo.ApiWmsDocLines powyzej
	JOIN
	(select * from dbo.ApiWmsDocLines where Id = @WmsLine) linia
	ON linia.ErpId = powyzej.ErpId and linia.DocumentId = powyzej.DocumentId and powyzej.Id< linia.Id)
	
	--,*
	 ,0);
	 return @res;
END



GO


