SET NOCOUNT ON

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'IsNameAutoGenerated'
    WHERE SysObjects.Name = 'ReservationAddress'
)
  ALTER TABLE ReservationAddress ADD IsNameAutoGenerated BIT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_ArrangementLineNumber'
    WHERE SysObjects.Name = 'Transactions'
)
  ALTER TABLE Transactions ADD FK_ArrangementLineNumber INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'Inactive'
    WHERE SysObjects.Name = 'Card'
)
  ALTER TABLE Card ADD Inactive BIT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RogerKeyCardAddKeyAction'
    WHERE SysObjects.Name = 'GuestTypes'
)
  ALTER TABLE GuestTypes ADD RogerKeyCardAddKeyAction SMALLINT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RogerKeyCardCheckOutAction'
    WHERE SysObjects.Name = 'GuestTypes'
)
  ALTER TABLE GuestTypes ADD RogerKeyCardCheckOutAction SMALLINT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RogerKeyCardAddKeyAction'
    WHERE SysObjects.Name = 'POINTOFSALES'
)
  ALTER TABLE POINTOFSALES ADD RogerKeyCardAddKeyAction SMALLINT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RogerKeyCardCheckOutAction'
    WHERE SysObjects.Name = 'POINTOFSALES'
)
  ALTER TABLE POINTOFSALES ADD RogerKeyCardCheckOutAction SMALLINT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RogerKeyCardAddKeyAction'
    WHERE SysObjects.Name = 'PURPOSECODES'
)
  ALTER TABLE PURPOSECODES ADD RogerKeyCardAddKeyAction SMALLINT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RogerKeyCardCheckOutAction'
    WHERE SysObjects.Name = 'PURPOSECODES'
)
  ALTER TABLE PURPOSECODES ADD RogerKeyCardCheckOutAction SMALLINT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RogerKeyCardAddKeyAction'
    WHERE SysObjects.Name = 'SEGMENTS'
)
  ALTER TABLE SEGMENTS ADD RogerKeyCardAddKeyAction SMALLINT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RogerKeyCardCheckOutAction'
    WHERE SysObjects.Name = 'SEGMENTS'
)
  ALTER TABLE SEGMENTS ADD RogerKeyCardCheckOutAction SMALLINT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ExternalAccommodationType'
    WHERE SysObjects.Name = 'GuestTypes'
)
  ALTER TABLE GuestTypes ADD ExternalAccommodationType VARCHAR(10) NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ExternalAccommodationType'
    WHERE SysObjects.Name = 'POINTOFSALES'
)
  ALTER TABLE POINTOFSALES ADD ExternalAccommodationType VARCHAR(10) NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ExternalAccommodationType'
    WHERE SysObjects.Name = 'PURPOSECODES'
)
  ALTER TABLE PURPOSECODES ADD ExternalAccommodationType VARCHAR(10) NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ExternalAccommodationType'
    WHERE SysObjects.Name = 'SEGMENTS'
)
  ALTER TABLE SEGMENTS ADD ExternalAccommodationType VARCHAR(10) NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'SessionTimeStamp'
    WHERE SysObjects.Name = 'ReservationMain'
)
  ALTER TABLE ReservationMain ADD SessionTimeStamp DATETIME NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ChangeDate'
    WHERE SysObjects.Name = 'IdentityFields'
)
  ALTER TABLE IdentityFields ADD ChangeDate SMALLDATETIME NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RatioInPercent'
    WHERE SysObjects.Name = 'AdditionalSalesFromTurnover'
)
  ALTER TABLE AdditionalSalesFromTurnover ADD RatioInPercent BIT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'Procentage'
    WHERE SysObjects.Name = 'MenuWareXTab'
)
  ALTER TABLE MenuWareXTab ADD Procentage INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ReservationStatus'
    WHERE SysObjects.Name = 'CustomerOrdreBook'
)
ALTER TABLE CustomerOrdreBook ADD ReservationStatus SMALLINT NOT NULL DEFAULT -1
GO


IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ReservationStatusNumber'
    WHERE SysObjects.Name = 'MISBudget'
)
begin
  IF EXISTS (SELECT name FROM SysIndexes  WITH (NOLOCK) WHERE name = 
            'PK_MISBudget')
  begin
	ALTER TABLE MISBudget
	Drop CONSTRAINT [PK_MISBudget]
  end

  ALTER TABLE MISBudget ADD ReservationStatusNumber INT NOT NULL DEFAULT -2

  ALTER TABLE MISBudget WITH NOCHECK
  ADD CONSTRAINT [PK_MISBudget] PRIMARY KEY CLUSTERED 
  (
	[SegmentNumber] ASC,
	[POSNumber] ASC,
	[RoomTypeNumber] ASC,
	[HallTypeNumber] ASC,
	[ReservationStatusNumber] ASC,
	[InclVAT] ASC,
	[HotelNumber] ASC,
	[TurnoverType] ASC,
	[FromDate] ASC,
	[ToDate] ASC,
	[ValueType] ASC,
	[PeriodType] ASC,
	[TypeValue] ASC
  ) ON [PRIMARY]

end
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects(NOLOCK) 
    INNER JOIN SysColumns(NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_DepartmentNumber'
    WHERE SysObjects.Name = 'AccountDaily'
)
  ALTER TABLE AccountDaily ADD FK_DepartmentNumber SMALLINT NULL 
GO

UPDATE AccountDaily SET FK_DepartmentNumber = -1
WHERE ISNULL(FK_DepartmentNumber, 0) = 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_DepartmentNumber'
    WHERE SysObjects.Name = 'BudgetMonth'
)
  ALTER TABLE BudgetMonth ADD FK_DepartmentNumber SMALLINT NULL 
GO

UPDATE BudgetMonth SET FK_DepartmentNumber = -1
WHERE ISNULL(FK_DepartmentNumber, 0) = 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_DepartmentNumber'
    WHERE SysObjects.Name = 'AdditionalSalesFromTurnover'
)
  ALTER TABLE AdditionalSalesFromTurnover ADD FK_DepartmentNumber SMALLINT NULL 
GO

UPDATE AdditionalSalesFromTurnover SET FK_DepartmentNumber = -1
WHERE ISNULL(FK_DepartmentNumber, 0) = 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_GiftTokenTypeId'
    WHERE SysObjects.Name = 'Ware'
)
  ALTER TABLE Ware ADD FK_GiftTokenTypeId INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'CancellationCodeType'
    WHERE SysObjects.Name = 'CancellationCodes'
)
  ALTER TABLE CancellationCodes ADD CancellationCodeType INT NULL 
GO

UPDATE CancellationCodes SET CancellationCodeType = 1 
WHERE ISNULL(CancellationCodeType, 0) = 0
GO

IF EXISTS
(
  SELECT * 
  FROM SysObjects WITH (NOLOCK) 
  WHERE SysObjects.Name = 'GiftTokenType'
)
  IF NOT EXISTS
  (
    SELECT SysColumns.Name 
    FROM SysObjects WITH (NOLOCK) 
      INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
      AND SysColumns.Name = 'FK_CardTemplate'
      WHERE SysObjects.Name = 'GiftTokenType'
  )
    ALTER TABLE GiftTokenType ADD FK_CardTemplate INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_Owner_WareGroupNumber'
    WHERE SysObjects.Name = 'RoomTypes'
)
  ALTER TABLE RoomTypes ADD FK_Owner_WareGroupNumber INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_Owner_WareNumber'
    WHERE SysObjects.Name = 'RoomTypes'
)
  ALTER TABLE RoomTypes ADD FK_Owner_WareNumber INT NULL 
GO

UPDATE TopWareList SET FK_WareGroupNumber = (SELECT WareGroupNumber FROM Ware WITH (NOLOCK) WHERE Ware.WareNumber = TopWareList.WareNumber)
WHERE ISNULL(FK_WareGroupNumber, 0) = 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RealDateTime'
    WHERE SysObjects.Name = 'Audit_Log_Transactions'
)
  ALTER TABLE Audit_Log_Transactions ADD RealDateTime DATETIME NULL 
GO

UPDATE Audit_Log_Transactions SET RealDateTime = Modified_Date
WHERE RealDateTime IS NULL
GO


IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns(NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_CategoryNumber'
    WHERE SysObjects.Name = 'CustomerProductCatGroupXtab'
)
  ALTER TABLE CustomerProductCatGroupXtab ADD FK_CategoryNumber INT NOT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_CategoryGroupTypeNumber'
    WHERE SysObjects.Name = 'GuestTypes'
)
  ALTER TABLE GuestTypes ADD FK_CategoryGroupTypeNumber INT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'IsProductPassed'
    WHERE SysObjects.Name = 'ReservationMeetingXtab'
)
  ALTER TABLE ReservationMeetingXtab ADD IsProductPassed BIT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ClothingLine'
    WHERE SysObjects.Name = 'Ware'
)
  ALTER TABLE Ware ADD ClothingLine VARCHAR(50) NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ClothingModel'
    WHERE SysObjects.Name = 'Ware'
)
  ALTER TABLE Ware ADD ClothingModel VARCHAR(50) NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ClothingColor'
    WHERE SysObjects.Name = 'Ware'
)
  ALTER TABLE Ware ADD ClothingColor VARCHAR(50) NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ClothingSize'
    WHERE SysObjects.Name = 'Ware'
)
  ALTER TABLE Ware ADD ClothingSize VARCHAR(50) NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ProvisionPostOnGuest'
    WHERE SysObjects.Name = 'ReservationAddress'
)
  ALTER TABLE ReservationAddress ADD ProvisionPostOnGuest BIT NOT NULL DEFAULT 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ProvisionPostOnGuest'
    WHERE SysObjects.Name = 'Customer'
)
  ALTER TABLE Customer ADD ProvisionPostOnGuest BIT NOT NULL DEFAULT 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ProvisionPostOnGuest'
    WHERE SysObjects.Name = 'CustomerFieldsPerHotel'
)
  ALTER TABLE CustomerFieldsPerHotel ADD ProvisionPostOnGuest BIT NOT NULL DEFAULT 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_CategoryType'
    WHERE SysObjects.Name = 'CustomerProductCatGroupXtab'
)
  ALTER TABLE CustomerProductCatGroupXtab ADD FK_CategoryType INT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ColourSetting'
    WHERE SysObjects.Name = 'Customer'
)
  ALTER TABLE Customer ADD ColourSetting INTEGER
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ExportAccountSummarized'
    WHERE SysObjects.Name = 'Accounts'
)
  ALTER TABLE Accounts ADD ExportAccountSummarized BIT NULL
GO

UPDATE Accounts SET ExportAccountSummarized = 0
WHERE ExportAccountSummarized IS NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'NoteRequired'
    WHERE SysObjects.Name = 'CancellationCodes'
)
  ALTER TABLE CancellationCodes ADD NoteRequired BIT NULL
GO

UPDATE CancellationCodes SET NoteRequired = 0 WHERE NoteRequired IS NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OwnerDiscountRate'
    WHERE SysObjects.Name = 'RESERVATIONADDRESS'
)
  ALTER TABLE RESERVATIONADDRESS ADD OwnerDiscountRate SmallMoney
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'MarkAsDeleted'
    WHERE SysObjects.Name = 'CONFERENCEROOMS'

)
  ALTER TABLE CONFERENCEROOMS ADD MarkAsDeleted bit
GO


IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_CertificateAttachmentID'
    WHERE SysObjects.Name = 'CustomerProductCatGroupXtab'
)
  ALTER TABLE CustomerProductCatGroupXtab ADD FK_CertificateAttachmentID INTEGER
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ExportDepartment'

    WHERE SysObjects.Name = 'DEPARTMENTS'
)
  ALTER TABLE DEPARTMENTS ADD ExportDepartment VARCHAR(50) NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_WareCategoryId'

    WHERE SysObjects.Name = 'Ware'
)
  ALTER TABLE Ware ADD FK_WareCategoryId INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects(NOLOCK) 
    INNER JOIN SysColumns(NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'Online'
    WHERE SysObjects.Name = 'GiftTokenType'
)
  ALTER TABLE GiftTokenType ADD Online BIT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name
  FROM SysObjects WITH (NOLOCK)
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID
    AND SysColumns.Name = 'IsMedicalsDelivered'
    WHERE SysObjects.Name = 'ReservationMeetingXtab'
)
  ALTER TABLE ReservationMeetingXtab ADD IsMedicalsDelivered BIT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'YieldNumber'
    WHERE SysObjects.Name = 'Customer'
)
BEGIN
  ALTER TABLE Customer ADD YieldNumber INTEGER
  ALTER TABLE Customer ADD CONSTRAINT FK_Customer_YieldNumber 
    FOREIGN KEY (YieldNumber)
    REFERENCES Yield (YieldNumber)
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'PaymentAtCheckin'
    WHERE SysObjects.Name = 'Customer'
)
  ALTER TABLE Customer ADD PaymentAtCheckin BIT NOT NULL DEFAULT 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OnlineBookingAllowed'
    WHERE SysObjects.Name = 'Customer'
)
  ALTER TABLE Customer ADD OnlineBookingAllowed BIT NOT NULL DEFAULT 1
GO

IF EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'CertificateExpiryDate'
    WHERE SysObjects.Name = 'ReservationTemplateProductXtab'
)
  ALTER TABLE ReservationTemplateProductXtab ALTER COLUMN CertificateExpiryDate DATETIME
GO


IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'CertificateExpiryDate'
    WHERE SysObjects.Name = 'ReservationTemplateProductXtab'
)
  ALTER TABLE ReservationTemplateProductXtab ADD CertificateExpiryDate DATETIME
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'PDFConversion'
    WHERE SysObjects.Name = 'Customer'
)
  ALTER TABLE Customer ADD PDFConversion BIT NOT NULL DEFAULT 1
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'DisAllowOverbooking'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD DisAllowOverbooking BIT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OnlineProductPrepaid'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD OnlineProductPrepaid  BIT NOT NULL DEFAULT 1
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'DIBSHotelID'
    WHERE SysObjects.Name = 'CUSTOMER'
)
  ALTER TABLE dbo.CUSTOMER ADD DIBSHotelID INT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OnlinePrepaidPercent'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD OnlinePrepaidPercent FLOAT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'NbrDaysBeforeLastSignUp'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD NbrDaysBeforeLastSignUp INT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'PublishProductOnline'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD PublishProductOnline BIT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_SubTemplateNumber'
    WHERE SysObjects.Name = 'Templates'
)
  ALTER TABLE Templates ADD FK_SubTemplateNumber INT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'BunkBed'
    WHERE SysObjects.Name = 'OnlineRoomTypes'
)
  ALTER TABLE dbo.OnlineRoomTypes ADD BunkBed BIT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OTAFunctionKind'
    WHERE SysObjects.Name = 'CustomerOTA'
)
  ALTER TABLE dbo.CustomerOTA ADD OTAFunctionKind INT NULL DEFAULT 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'CurrencyActiveOnline'
    WHERE SysObjects.Name = 'Countries'
)
  ALTER TABLE Countries ADD CurrencyActiveOnline bit not null default 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'Alias'
    WHERE SysObjects.Name = 'SplitBill'
)
  ALTER TABLE SplitBill ADD Alias VARCHAR(300)
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RoomNamelistAdded'
    WHERE SysObjects.Name = 'ReservationMeetingXTab'
)
  ALTER TABLE ReservationMeetingXTab ADD RoomNamelistAdded bit not null default 0
GO

-- BA/20140106: CR067924/Change Address1..3 from 50 to 100 characters.
if (SELECT CHARACTER_MAXIMUM_LENGTH
    FROM INFORMATION_SCHEMA.COLUMNS  
    WHERE TABLE_NAME = 'Customer' AND COLUMN_NAME = 'Address1') < 100
BEGIN
  ALTER TABLE Customer ALTER COLUMN Address1 VARCHAR(100) NULL
  ALTER TABLE Customer ALTER COLUMN Address2 VARCHAR(100) NULL
  ALTER TABLE Customer ALTER COLUMN Address3 VARCHAR(100) NULL
  ALTER TABLE ReservationAddress ALTER COLUMN Address1 VARCHAR(100) NULL
  ALTER TABLE ReservationAddress ALTER COLUMN Address2 VARCHAR(100) NULL
  ALTER TABLE ReservationAddress ALTER COLUMN Address3 VARCHAR(100) NULL
END    
IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RedWEBPaymentID'
    WHERE SysObjects.Name = 'ReservationMeetingXtab'
)
  ALTER TABLE ReservationMeetingXtab ADD RedWEBPaymentID VARCHAR(255)
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_SplitBillNumber'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD FK_SplitBillNumber INT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'DoEncryptCreditCard'
    WHERE SysObjects.Name = 'Reservations'
)
  ALTER TABLE Reservations ADD DoEncryptCreditCard BIT NULL
GO

-- BA/20140130: New EnableAssociatedProducts field added to CampaignCodesHotel table
IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'EnableAssociatedProducts'
    WHERE SysObjects.Name = 'CampaignCodesHotel'
)
  ALTER TABLE CampaignCodesHotel ADD EnableAssociatedProducts BIT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'DefaultTableBookingMinutes'
    WHERE SysObjects.Name = 'CONFERENCEROOMTYPES'
)
BEGIN
  ALTER TABLE CONFERENCEROOMTYPES ADD DefaultTableBookingMinutes INT not null default 0
END

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ParentRoomNumber'
    WHERE SysObjects.Name = 'Rooms'
)
  ALTER TABLE Rooms ADD ParentRoomNumber INT NULL
GO

IF NOT EXISTS (SELECT name FROM SysIndexes WITH (NOLOCK) WHERE name = 
            'IX_Rooms_ParentRoomNumber')
	CREATE NONCLUSTERED INDEX [IX_Rooms_ParentRoomNumber] ON [dbo].[Rooms] 
	(
		[ParentRoomNumber] ASC
	)
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ParentRoomTypeNumber'
    WHERE SysObjects.Name = 'RoomTypes'
)
  ALTER TABLE RoomTypes ADD ParentRoomTypeNumber INT NULL
GO

IF NOT EXISTS (SELECT name FROM SysIndexes WITH (NOLOCK) WHERE name = 
            'IX_RoomTypes_ParentRoomTypeNumber')
	CREATE NONCLUSTERED INDEX [IX_RoomTypes_ParentRoomTypeNumber] ON [dbo].[RoomTypes] 
	(
		[ParentRoomTypeNumber] ASC
	)
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'NumberOfChildRooms'
    WHERE SysObjects.Name = 'RoomTypes'
)
  ALTER TABLE RoomTypes ADD NumberOfChildRooms INT NOT NULL DEFAULT 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'NumberOfNotSaleable'
    WHERE SysObjects.Name = 'RoomBookingStatus'
)
  ALTER TABLE RoomBookingStatus ADD NumberOfNotSaleable INT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'SoldSubRooms'
    WHERE SysObjects.Name = 'RoomBookingStatus'
)
  ALTER TABLE RoomBookingStatus ADD SoldSubRooms INT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ProductPricePerHour'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD ProductPricePerHour BIT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'SetOneSegment'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD SetOneSegment BIT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'SetOnePOS'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD SetOnePOS BIT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'PAX2'
    WHERE SysObjects.Name = 'Schedule'
)
  ALTER TABLE Schedule ADD PAX2 INT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'MinPax'
    WHERE SysObjects.Name = 'OnlineRoomTypes'
)
  ALTER TABLE OnlineRoomTypes ADD MinPax TINYINT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ContainerSubType'
    WHERE SysObjects.Name = 'RoomTypes'
)
  ALTER TABLE RoomTypes ADD ContainerSubType BIT NOT NULL DEFAULT 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ProductOrderID'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD ProductOrderID VARCHAR(255)
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'SetProductOrderIDOnRes'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD SetProductOrderIDOnRes BIT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ProductOnlineClosedtoArrivaldays'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD ProductOnlineClosedtoArrivaldays INT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_WareNumber'
    WHERE SysObjects.Name = 'DebtorAccounting'
)
  ALTER TABLE DebtorAccounting ADD FK_WareNumber INT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_AccountNumberPayment'
    WHERE SysObjects.Name = 'DebtorAccounting'
)
  ALTER TABLE DebtorAccounting ADD FK_AccountNumberPayment INT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ProductCurrencyCode'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD ProductCurrencyCode INT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ProductCurrencyRateDate'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD ProductCurrencyRateDate datetime NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ProductCurrencyRate'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD ProductCurrencyRate money NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ForceEndTimeOnArrangement'
    WHERE SysObjects.Name = 'Ware'
)
  ALTER TABLE Ware ADD ForceEndTimeOnArrangement BIT null
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'VATcode'
    WHERE SysObjects.Name = 'POINTOFSALES'
)
  ALTER TABLE POINTOFSALES ADD VATcode SMALLINT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'AriadneShowArrAsOccupied'
    WHERE SysObjects.Name = 'RESERVATIONS'
)
  ALTER TABLE RESERVATIONS ADD AriadneShowArrAsOccupied BIT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'AriadneDoNotShowOnInfo'
    WHERE SysObjects.Name = 'RESERVATIONS'
)
  ALTER TABLE RESERVATIONS ADD AriadneDoNotShowOnInfo BIT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'StatusRL'
    WHERE SysObjects.Name = 'ReservationRoomline'
)
  ALTER TABLE ReservationRoomline ADD StatusRL int null
  
GO

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OnlineHallImagesXTab]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
	CREATE TABLE [dbo].[OnlineHallImagesXTab](
		[ConferenceRoomNumber] int NOT NULL,
		[ImageName] VARCHAR(255) NOT NULL,
                [SortOrder] int NOT NULL
	
	CONSTRAINT [PK_OnlineHallsImagesXTab_1] PRIMARY KEY CLUSTERED 
	(
		[ConferenceRoomNumber], [ImageName] ASC
	)
)

	ALTER TABLE [dbo].[OnlineHallImagesXTab]  WITH NOCHECK ADD  CONSTRAINT [FK_OnlineHallImages_OnlineHalls] FOREIGN KEY([ConferenceRoomNumber])
	REFERENCES [dbo].[ConferenceRooms] ([ConferenceRoomNumber])

	ALTER TABLE [dbo].[OnlineHallImagesXTab] CHECK CONSTRAINT [FK_OnlineHallImages_OnlineHalls]

END
GO

alter table ConferenceRooms alter column Description VarChar(Max)
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'SortNumber'
    WHERE SysObjects.Name = 'CustomerImagesXTab'
)
  ALTER TABLE CustomerImagesXTab ADD SortNumber INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'SortNumber'
    WHERE SysObjects.Name = 'OnlineRoomTypesImagesXTab'
)
  ALTER TABLE OnlineRoomTypesImagesXTab ADD SortNumber INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'SortNumber'
    WHERE SysObjects.Name = 'ProductsImagesXTab'
)
  ALTER TABLE ProductsImagesXTab ADD SortNumber INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'Duration'
    WHERE SysObjects.Name = 'OnlineWareDelivery'
)
  ALTER TABLE OnlineWareDelivery ADD Duration INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OnlineBookingTimeInterval'
    WHERE SysObjects.Name = 'ConferenceRooms'
)
  ALTER TABLE ConferenceRooms ADD OnlineBookingTimeInterval int null

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'UseType'
    WHERE SysObjects.Name = 'RoomTypes'
)
  ALTER TABLE RoomTypes ADD UseType int not null default 0

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'AutoAssignRoom'
    WHERE SysObjects.Name = 'RoomTypes'
)
  ALTER TABLE RoomTypes ADD AutoAssignRoom BIT not null default 0

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'AutoCheckIn'
    WHERE SysObjects.Name = 'RoomTypes'
)
  ALTER TABLE RoomTypes ADD AutoCheckIn BIT not null default 0

GO

IF NOT EXISTS (SELECT name FROM SysIndexes WITH (NOLOCK) WHERE name = 
            'IX_ArrangementReservationConferenceLineXtab')
	CREATE NONCLUSTERED INDEX [IX_ArrangementReservationConferenceLineXtab] ON [dbo].[ArrangementReservationConferenceLineXtab] 
	(
		[ArrangementLineNumber] ASC,
		[ReservationConfLineNumber] ASC
	)
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_ReservationGroup'
    WHERE SysObjects.Name = 'Reservations'
)
  ALTER TABLE Reservations ADD FK_ReservationGroup INT null

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_ReservationGroup'
    WHERE SysObjects.Name = 'ReservationRoomLine'
)
  ALTER TABLE ReservationRoomLine ADD FK_ReservationGroup INT null

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ReservationGroup'
    WHERE SysObjects.Name = 'RoomBookingStatus'
)
BEGIN
  ALTER TABLE RoomBookingStatus ADD ReservationGroup INT NOT null Default 0

  Alter TABLE RoomBookingStatus DROP CONSTRAINT PK_ROOMBOOKINGSTATUS

  Alter TABLE RoomBookingStatus
  ADD CONSTRAINT PK_ROOMBOOKINGSTATUS PRIMARY KEY CLUSTERED (DateStamp DESC, RoomTypeNumber, SegmentNumber, PointOfSaleNumber,HotelNumber,SoldRoomType, ReservationGroup)
END

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'NumberOfOccupiedGroup'
    WHERE SysObjects.Name = 'RoomBookingStatus'
)
  ALTER TABLE RoomBookingStatus ADD NumberOfOccupiedGroup INT null

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OutlookEntryID'
    WHERE SysObjects.Name = 'ReservationMeetingXtab'
)
  ALTER TABLE ReservationMeetingXtab ADD OutlookEntryID VARCHAR(MAX) NULL

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OutlookMailboxAddress'
    WHERE SysObjects.Name = 'ReservationMeetingXtab'
)
  ALTER TABLE ReservationMeetingXtab ADD OutlookMailboxAddress VARCHAR(MAX) NULL

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ReservationGroup]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	IF NOT EXISTS
	(
	  SELECT SysColumns.Name 
	  FROM SysObjects WITH (NOLOCK) 
		INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
		AND SysColumns.Name = 'Code'
		WHERE SysObjects.Name = 'ReservationGroup'
	)
	  ALTER TABLE ReservationGroup ADD Code VARCHAR(10) NULL

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'NotWanted'
    WHERE SysObjects.Name = 'Customer'
)
  ALTER TABLE Customer ADD NotWanted BIT NULL

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'StayCleanInterval'
    WHERE SysObjects.Name = 'RoomTypes'
)
  ALTER TABLE RoomTypes ADD StayCleanInterval INT NULL

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'LeaveRoomCount'
    WHERE SysObjects.Name = 'Rooms'
)
  ALTER TABLE Rooms ADD LeaveRoomCount INT NULL

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'MailRule'
    WHERE SysObjects.Name = 'Customer'
)
  ALTER TABLE Customer ADD MailRule TINYINT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'MailRuleConfirmations'
    WHERE SysObjects.Name = 'Customer'
)
  ALTER TABLE Customer ADD MailRuleConfirmations TINYINT NULL
GO

IF EXISTS (SELECT 1 FROM sys.objects WHERE NAME = 'FK_Transactions_ArrangementLines' AND TYPE = 'F')
BEGIN
  ALTER TABLE Transactions DROP CONSTRAINT FK_Transactions_ArrangementLines
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'AutoConfirmed'
    WHERE SysObjects.Name = 'ReservationMain'
)
  ALTER TABLE ReservationMain ADD AutoConfirmed TINYINT NOT NULL DEFAULT 0 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'AutoConfirmed'
    WHERE SysObjects.Name = 'Reservations'
)
  ALTER TABLE Reservations ADD AutoConfirmed TINYINT NOT NULL DEFAULT 0 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'TemplateNumber'
    WHERE SysObjects.Name = 'Reservations'
)
BEGIN
  ALTER TABLE Reservations ADD TemplateNumber INTEGER 
  ALTER TABLE Reservations ADD CONSTRAINT FK_Reservations_TemplateNumber 
    FOREIGN KEY (TemplateNumber)
    REFERENCES Templates (TemplateNumber)
END
GO

IF EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ScreenDump'
    WHERE SysObjects.Name = 'ErrorLog'
)
  ALTER TABLE ErrorLog ALTER COLUMN ScreenDump image
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'PAX'
    WHERE SysObjects.Name = 'OnlineRoomTypesTranslated'
)
  ALTER TABLE OnlineRoomTypesTranslated ADD PAX INT NOT NULL DEFAULT 0 

  Alter TABLE OnlineRoomTypesTranslated DROP CONSTRAINT PK_OnlineRoomTypesTranslated

  Alter TABLE OnlineRoomTypesTranslated
  ADD CONSTRAINT PK_OnlineRoomTypesTranslated PRIMARY KEY CLUSTERED (OnlineRoomTypeNumber, CountryNumber, PAX)
IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OTACode'
    WHERE SysObjects.Name = 'WareCategory'
)
  ALTER TABLE WareCategory ADD OTACode VARCHAR(50) NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OTAType'
    WHERE SysObjects.Name = 'WareCategory'
)
  ALTER TABLE WareCategory ADD OTAType SMALLINT NULL
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID('dbo.MISTotals') AND type in (N'U'))
BEGIN
    CREATE TABLE dbo.MISTotals(
    SystemDate DateTime,
    DateStamp VarChar(8),
    ReferenceNumber Int, 
    BookedPrice Money,
    ActualPrice Money
    ) 
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OwnerSettlementPercentOwnUse'
    WHERE SysObjects.Name = 'Rooms'
)
  ALTER TABLE Rooms ADD OwnerSettlementPercentOwnUse FLOAT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OwnerSettlementPercentReferral'
    WHERE SysObjects.Name = 'Rooms'
)
  ALTER TABLE Rooms ADD OwnerSettlementPercentReferral FLOAT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OwnerCreditCardFee'
    WHERE SysObjects.Name = 'Ware'
)
  ALTER TABLE Ware ADD OwnerCreditCardFee BIT NULL
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID('dbo.ProductTemplateXTab') AND type in (N'U'))
BEGIN
  CREATE TABLE dbo.ProductTemplateXTab(
	FK_ProductNumber int NOT NULL,
	FK_TemplateNumber int NOT NULL
  )
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'GroupName'
    WHERE SysObjects.Name = 'Reservations'
)
BEGIN
  ALTER TABLE Reservations ADD GroupName VARCHAR(50) NULL

  CREATE NONCLUSTERED INDEX [IX_RESERVATIONS_GroupName] ON [dbo].[RESERVATIONS]
(
	[GroupName] ASC
)
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'IsGWOCourse'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD IsGWOCourse BIT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'IsDefaultSetupForHall'
    WHERE SysObjects.Name = 'ConferenceRoomSetup'
)
  ALTER TABLE ConferenceRoomSetup ADD IsDefaultSetupForHall BIT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'UseInstructorSignature'
    WHERE SysObjects.Name = 'ReservationMeetingXTab'
)
  ALTER TABLE ReservationMeetingXTab ADD UseInstructorSignature BIT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'CustomCertificateNumber'
    WHERE SysObjects.Name = 'ReservationMeetingXTab'
)
  ALTER TABLE ReservationMeetingXTab ADD CustomCertificateNumber VARCHAR(255) NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ForceCustomCertificateNumber'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD ForceCustomCertificateNumber BIT NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'Type'
    WHERE SysObjects.Name = 'ProductsProductsXtab'
)
  ALTER TABLE ProductsProductsXtab ADD Type INT NOT NULL DEFAULT 0
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_GovermentWareTypeId'
    WHERE SysObjects.Name = 'Ware'
)
  ALTER TABLE Ware ADD FK_GovermentWareTypeId INT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'SubjectLine'
    WHERE SysObjects.Name = 'Templates'
)
  ALTER TABLE Templates ADD SubjectLine VARCHAR(200)
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'Active'
    WHERE SysObjects.Name = 'Templates'
)
  ALTER TABLE Templates ADD Active BIT NOT NULL DEFAULT 1
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'CardTerminalIdNumber'
    WHERE SysObjects.Name = 'Terminals'
)
  ALTER TABLE Terminals ADD CardTerminalIdNumber VARCHAR(50)
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OnlineProductSortNumber'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD OnlineProductSortNumber INT NULL
GO

-- RQ3043: Alter ReservationAddress.BuyersOrderID from size 15 to 30.
DECLARE @DataSize INT
SELECT @DataSize = COLUMNPROPERTY(OBJECT_ID('ReservationAddress'), 'BuyersOrderID', 'PRECISION')
IF (@DataSize < 30)
ALTER TABLE ReservationAddress
  ALTER COLUMN BuyersOrderID VARCHAR(30) NULL
GO

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ViewLog1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[ViewLog1](
	[FkViewLineId] int NOT NULL,
	[ViewId] int NOT NULL,
    [FkPicassoLog] int NOT NULL
	
	CONSTRAINT [PK_ViewLog1] PRIMARY KEY CLUSTERED 
	(
		[FkViewLineId], [ViewId], [FkPicassoLog] ASC
	)
  )
END

GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RecalcPricesOnCurrRateChg'
    WHERE SysObjects.Name = 'ProductExtended'
)
  ALTER TABLE ProductExtended ADD RecalcPricesOnCurrRateChg BIT NOT NULL DEFAULT ((1))
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'Type_'
    WHERE SysObjects.Name = 'Templates'
)
BEGIN
  ALTER TABLE Templates ADD Type_ INT NULL
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'Language_'
    WHERE SysObjects.Name = 'Templates'
)
BEGIN
  ALTER TABLE Templates ADD Language_ VARCHAR(5) NULL
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'WindaId'
    WHERE SysObjects.Name = 'Customer'
)
  ALTER TABLE Customer ADD WindaId VARCHAR(20) NULL
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'GWOExpiryDate'
    WHERE SysObjects.Name = 'ReservationMeetingXTab'
)
  ALTER TABLE ReservationMeetingXTab ADD GWOExpiryDate datetime NULL
GO
