CREATE FUNCTION [dbo].[GetTransactionWareGroupPayment] (@ATransactionNumber int)  
RETURNS smallint AS  
BEGIN 
  DECLARE @Payment smallint
  
  SELECT @Payment = WareGroups.Payment FROM WareGroups WITH (NOLOCK)
  INNER JOIN Ware WITH (NOLOCK) ON
    Ware.WareGroupNumber = WareGroups.WareGroupNumber
  INNER JOIN Transactions WITH (NOLOCK) ON
    Transactions.WareNumber = Ware.WareNumber AND
    Transactions.TransactionNumber = @ATransactionNumber

  IF @Payment IS NULL
    SET @Payment = 0

  RETURN @Payment
END

