if (select count(*) from syscolumn where column_name='TakenOrder' and table_id=(select table_id from systable where table_name='Guests')) =0 then alter table Guests add TakenOrder integer default 1; end if; go IF (EXISTS(Select * from sys.systable where LCase(table_name) = LCase('v_TakenOrdersByGuests'))) THEN Drop view v_TakenOrdersByGuests END IF GO create view DBA.v_TakenOrdersByGuests as select G.GuestNum, G.Name as GuestName, G.EGN as EGN, G.FN as FN, G.NumZN as NumZN, G.DateZN as DateZN, (if (G.TakenOrder=1) then 'ДА' else 'НЕ' endif) as TakenOrder from Guests G GO delete from Relations where RelationTable='Взети настанителни заповеди' GO insert into "Relations" ("TableName", "ColName", "BGTableName", "BGColName", "RelationTable", "RelationCol", "SelectCol", "N", "Function", "Suma", "Mask", "Align", "Sortirane", "Zadaljitelna", "Promenliva", "FilterList", "DftFilter", "Shirina", "Opisanie", "DftLike", "AutoStretch", "Spravka", "PoslData") values('v_TakenOrdersByGuests', '__OPTIONS__', 'Взети настанителни заповеди', '__OPTIONS__', 'Взети настанителни заповеди', '__OPTIONS__', 1, GetFreeNInRelations('Взети настанителни заповеди',null,null,5), '__OPTIONS__', '', '', 0, 0, '', '', '', '', 1, '', 0, 0, 1, today()); GO insert into "Relations" ("TableName", "ColName", "BGTableName", "BGColName", "RelationTable", "RelationCol", "SelectCol", "N", "Function", "Suma", "Mask", "Align", "Sortirane", "Zadaljitelna", "Promenliva", "FilterList", "DftFilter", "Shirina", "Opisanie", "DftLike", "AutoStretch", "Spravka", "PoslData") values('v_TakenOrdersByGuests', 'GuestName', 'Взети настанителни заповеди', 'Име на студент', 'Взети настанителни заповеди', 'GuestName', 2, GetFreeNInRelations('Взети настанителни заповеди',null,null,5), 'GuestName', '', '', 0, 0, '', '', '', '', 200, '', 0, 0, 1, today()); GO insert into "Relations" ("TableName", "ColName", "BGTableName", "BGColName", "RelationTable", "RelationCol", "SelectCol", "N", "Function", "Suma", "Mask", "Align", "Sortirane", "Zadaljitelna", "Promenliva", "FilterList", "DftFilter", "Shirina", "Opisanie", "DftLike", "AutoStretch", "Spravka", "PoslData") values('v_TakenOrdersByGuests', 'EGN', 'Взети настанителни заповеди', 'ЕГН', 'Взети настанителни заповеди', 'EGN', 2, GetFreeNInRelations('Взети настанителни заповеди',null,null,5), 'EGN', '', '', 0, 0, '', '', '', '', 100, '', 0, 0, 1, today()); GO insert into "Relations" ("TableName", "ColName", "BGTableName", "BGColName", "RelationTable", "RelationCol", "SelectCol", "N", "Function", "Suma", "Mask", "Align", "Sortirane", "Zadaljitelna", "Promenliva", "FilterList", "DftFilter", "Shirina", "Opisanie", "DftLike", "AutoStretch", "Spravka", "PoslData") values('v_TakenOrdersByGuests', 'FN', 'Взети настанителни заповеди', 'Фак. №', 'Взети настанителни заповеди', 'FN', 2, GetFreeNInRelations('Взети настанителни заповеди',null,null,5), 'FN', '', '', 0, 0, '', '', '', '', 100, '', 0, 0, 1, today()); GO insert into "Relations" ("TableName", "ColName", "BGTableName", "BGColName", "RelationTable", "RelationCol", "SelectCol", "N", "Function", "Suma", "Mask", "Align", "Sortirane", "Zadaljitelna", "Promenliva", "FilterList", "DftFilter", "Shirina", "Opisanie", "DftLike", "AutoStretch", "Spravka", "PoslData") values('v_TakenOrdersByGuests', 'NumZN', 'Взети настанителни заповеди', 'Номер на заповед', 'Взети настанителни заповеди', 'NumZN', 2, GetFreeNInRelations('Взети настанителни заповеди',null,null,5), 'NumZN', '', '', 0, 0, '', '', '', '', 120, '', 0, 0, 1, today()); GO insert into "Relations" ("TableName", "ColName", "BGTableName", "BGColName", "RelationTable", "RelationCol", "SelectCol", "N", "Function", "Suma", "Mask", "Align", "Sortirane", "Zadaljitelna", "Promenliva", "FilterList", "DftFilter", "Shirina", "Opisanie", "DftLike", "AutoStretch", "Spravka", "PoslData") values('v_TakenOrdersByGuests', 'DateZN', 'Взети настанителни заповеди', 'Дата на заповед', 'Взети настанителни заповеди', 'DateZN', 2, GetFreeNInRelations('Взети настанителни заповеди',null,null,5), 'DateZN', '', '', 0, 0, '', '', '', '', 120, '', 0, 0, 1, today()); GO insert into "Relations" ("TableName", "ColName", "BGTableName", "BGColName", "RelationTable", "RelationCol", "SelectCol", "N", "Function", "Suma", "Mask", "Align", "Sortirane", "Zadaljitelna", "Promenliva", "FilterList", "DftFilter", "Shirina", "Opisanie", "DftLike", "AutoStretch", "Spravka", "PoslData") values('v_TakenOrdersByGuests', 'TakenOrder', 'Взети настанителни заповеди', 'Взета', 'Взети настанителни заповеди', 'TakenOrder', 2, GetFreeNInRelations('Взети настанителни заповеди',null,null,5), 'TakenOrder', '', '', 0, 0, '', '', 'Select ''ДА'' union Select ''НЕ''', '', 60, '', 0, 0, 1, today()); GO Call InsertPravaSpravki('Взети настанителни заповеди'); GO