CREATE FUNCTION [dbo].[GetDiscountWareInfo] ()  
RETURNS @Result TABLE (
  DiscountWareNumber int NOT NULL,
  DiscountResultAccountNumber int NOT NULL,
  DiscountVatValueWare float NOT NULL) AS 
BEGIN
 
-- OF 20120601: Ext: Discount Trial.
-- OF 20120522: New 

	DECLARE @DiscountWareNumber INT
	DECLARE @DiscountResultAccountNumber INT
	DECLARE @VatValueNumber INT
	DECLARE @DiscountVatValueWare FLOAT	

	INSERT INTO @Result
	SELECT WareNumber, ResultAccountNumber, ISNULL(dbo.GetVatPercent(Accounts.VatValueNumber), 0)
	FROM Ware WITH (NOLOCK) 
	INNER JOIN  WareGroups WITH (NOLOCK) ON Ware.WareGroupNumber = WareGroups.WareGroupNumber
	INNER JOIN Accounts WITH (NOLOCK) ON Accounts.AccountNumber = Ware.ResultAccountNumber
	WHERE Ware.SortNumber=10
	AND Ware.MarkAsDeleted IS NULL
	AND WareGroups.Payment=5 
	AND ((WareGroups.MarkAsDeleted is null) OR (WareGroups.MarkAsDeleted='0')) 

RETURN

END

