SET NOCOUNT ON
DECLARE @HotelCustomerNumber INT
IF NOT EXISTS(SELECT * FROM IdentityFields WHERE DBTableName = 'CashBoxReportPrintCopyIdentity')
BEGIN
  DECLARE db_cur CURSOR FOR
    SELECT CustomerNumber FROM Customer WITH (NOLOCK) WHERE CustomerTypeNumber = 7 AND ISNULL(MarkAsDeleted, 0) = 0 AND HotelNumber >= 0
  OPEN db_cur
  
  FETCH NEXT FROM db_cur INTO @HotelCustomerNumber
  
  WHILE @@FETCH_STATUS = 0
  BEGIN
    INSERT INTO IdentityFields (DBTableName, HotelCustomerNumber, IdentityField, FKDepartment, Changedate) VALUES ('CASHBOXREPORTPRINTCOPYIDENTITY', @HotelCustomerNumber, 0, -1, GETDATE())
    FETCH NEXT FROM db_cur INTO @HotelCustomerNumber
  END
  CLOSE db_cur
  DEALLOCATE db_cur
END

IF NOT EXISTS(SELECT * FROM IdentityFields WHERE DBTableName = 'CashBoxXReportPrintIdentity')
BEGIN
  DECLARE db_cur1 CURSOR FOR
    SELECT CustomerNumber FROM Customer WITH (NOLOCK) WHERE CustomerTypeNumber = 7 AND ISNULL(MarkAsDeleted, 0) = 0 AND HotelNumber >= 0
  OPEN db_cur1
  
  FETCH NEXT FROM db_cur1 INTO @HotelCustomerNumber
  
  WHILE @@FETCH_STATUS = 0
  BEGIN
    INSERT INTO IdentityFields (DBTableName, HotelCustomerNumber, IdentityField, FKDepartment, Changedate) VALUES ('CASHBOXXREPORTPRINTIDENTITY', @HotelCustomerNumber, 0, -1, GETDATE())
    FETCH NEXT FROM db_cur1 INTO @HotelCustomerNumber
  END
  CLOSE db_cur1
  DEALLOCATE db_cur1
END