IF (Exists(select Table_name from SysTable where LCase(Table_name)=LCase('v_New_StatisticsByCountry'))) THEN Drop view v_New_StatisticsByCountry END IF Go Create View v_New_StatisticsByCountry AS SELECT DISTINCT B.Guest, B.Room, G.NativeCountry, C.Description, G.AdultType, B.ContractPays, NumLodgings = DateIntersection(B.DateRegDt,B.DateRegDt+B.NumLodgings,bvrData1,bvrData2), NewLodgings = (if B.DateRegDt >= bvrData1 then 1 else 0 endif), DateReg = B.DateRegDt FROM Book as B, Guests as G, Countries as C WHERE B.Guest = G.GuestNum AND G.NativeCountry = C.CountryKod AND G.Status<>0 //AND (B.RegDateDt + B.NumLodgings >= BvrData1) //AND (B.RegDateDt <= BvrData2) AND DateIntersection(B.DateRegDt,B.DateRegDt+B.NumLodgings,bvrData1,bvrData2)>0 // pomoshtno view za spravkata "statistika po strani" //[17.August.2006] - Yanko