IF EXISTS (SELECT * FROM dbo.SysObjects WHERE id = object_id(N'dbo.TRIGGERTRIGGER_ReservationCreateDate') AND OBJECTPROPERTY(id, N'IsTrigger') = 1) DROP TRIGGER dbo.TRIGGERTRIGGER_ReservationCreateDate
GO
CREATE TRIGGER [dbo].[TRIGGERTRIGGER_ReservationCreateDate] ON [dbo].[Reservations] AFTER INSERT AS
BEGIN
  SET NOCOUNT ON

  DECLARE @ReferenceNumber INT
  DECLARE @GuestNumber INT
  DECLARE @SystemDateTime DATETIME

  EXEC SystemDateTime '', @SystemDateTime OUTPUT

  DECLARE db_cur CURSOR LOCAL FAST_FORWARD FOR
    SELECT ReferenceNumber, GuestNumber FROM inserted
  OPEN db_cur

  FETCH NEXT FROM db_cur INTO @ReferenceNumber, @GuestNumber

  WHILE @@FETCH_STATUS = 0
  BEGIN
    UPDATE Reservations SET ReservationCreateDate = @SystemDateTime
    WHERE Reservations.ReferenceNumber = @ReferenceNumber
    AND Reservations.GuestNumber = @GuestNumber

    FETCH NEXT FROM db_cur INTO @ReferenceNumber, @GuestNumber
  END
  CLOSE db_cur
  DEALLOCATE db_cur
END