IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FkProjectCode'
    WHERE SysObjects.Name = 'Folios'
)
  ALTER TABLE Folios ADD FkProjectCode INTEGER
GO
IF (SELECT ISNULL(CONVERT(bit, dbo.GetHotelSetupKeyValue('ProjectSystemAdvancedEnabled', -1)), 0)) = 1
  UPDATE FOLIOS 
    SET FkProjectCode = (SELECT TOP 1 ProjectNumber FROM FolioProjectXTab FPX (NOLOCK) WHERE FPX.FolioNumber = Folios.FolioNumber)
  WHERE FOLIOS.FkProjectCode IS NULL
