IF EXISTS (SELECT * FROM dbo.SysObjects WHERE id = object_id(N'dbo.ArrangementLineIllegalWare') AND OBJECTPROPERTY(id, N'IsTrigger') = 1) DROP TRIGGER dbo.ArrangementLineIllegalWare 
GO
CREATE TRIGGER dbo.ArrangementLineIllegalWare ON ArrangementLines AFTER INSERT, UPDATE AS
BEGIN
  SET NOCOUNT ON
  DECLARE @Payment INT

  SELECT @Payment = WareGroups.Payment
  FROM WareGroups WITH (NOLOCK)
  INNER JOIN Ware WITH (NOLOCK) ON Ware.WareGroupNumber = WareGroups.WareGroupNumber
    AND Ware.WareNumber = (SELECT WareNumber FROM INSERTED)

  IF @Payment = 1
  BEGIN
    ROLLBACK TRAN
    RAISERROR ( 'Trigger.ArrangementLineIllegalWare: Illegal ware on arrangement line', 16, 1)
  END
END