IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'dbo.TRIGGER_RateLevelRoomTypeRestrictionXTab_HistAfterInsert'))
DROP TRIGGER dbo.TRIGGER_RateLevelRoomTypeRestrictionXTab_HistAfterInsert
GO

CREATE TRIGGER dbo.TRIGGER_RateLevelRoomTypeRestrictionXTab_HistAfterInsert ON RateLevelRoomTypeRestrictionXTab AFTER INSERT, UPDATE AS
/*
  Created by Kent Johansen, december 2021
*/

BEGIN
  SET NOCOUNT ON;

  INSERT INTO RateLevelRoomTypeRestrictionXTab_Hist
  SELECT FKRateLevelRoomTypeXTabId, FKRateLevelRestrictionId, DateStamp, RestrictionLength, RoomsAllocated, RoomsAvailableRoomType, RoomsAvailableTotal, GETDATE()
  FROM inserted
  WHERE DoNotLog <> 1
END