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 @SystemdateStr CHAR(8)
  DECLARE @SystemDateTime DATETIME

  SELECT TOP 1 @SystemdateStr = SystemDate FROM System WITH (NOLOCK)
  SET @SystemDateTime = CONVERT(DATETIME, @SystemDateStr + ' ' + CONVERT(CHAR(8), CURRENT_TIMESTAMP, 108))

  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