IF (EXISTS(Select * from sys.systable where LCase(table_name) = LCase('v_ExportGuests')))
THEN Drop view v_ExportGuests
END IF

GO

create view
  DBA.v_ExportGuests
  as select TableName='Guests',VersionNo='2',
    HotelID=(select IntStojnost from DBA.Registers where RegisterName = 'HotelID'),
    GuestNum,
    HumanKind,
    Name,
    NameLatin,
    EGN,
    Address,
    PassportSeria,
    PassportNumber,
    PassportDate,
    PassportWhere,
    KPP,
    Goal,
    CountryArrive,
    BirthDate,
    NativeCountry,
    City,
    Reservation,
    "Group",
    HasData,
    Note,
    TipVaulcher,
    CreditLimit,
    TipVip,
    Sex,
    Contract,
    BoardPlanDef,
    ResNumLogin,
    ReservePlanNo,
    ResPriceKind,
    Status,
    BirthDateDt,
    PassportDateDt,
    DepositSum,
    ServiceSum,
    HourArrive,
    HourLeaving,
    VaulcherNo,
    AccountType,
    BlackSheep,
    Balance,
    SafeNo,
    OfficialNum,
    DateEnterBG,
    AdultType,History='',
    TogetherWith,
    CardN,
    PaspValDate,
    RoomType,
    PaspValidity,
    Note2,
    IsEgnEnch,
    Nationality,
    SettlementN,
    NumZN,
    DateZN,
    FN,
    Kurs,
    SpecNo,
    UniN,
    IsInAdminSoftDB,
    ServiceCreditsSum,
    PhotoId,
    CategoryN
	from
    DBA.Guests where
    LastChanged > bvrExportData