IF (EXISTS(Select * from sys.sysprocedure where LCase(proc_name) = LCase('CalcOccupiedOnlineRooms')))
THEN Drop procedure CalcOccupiedOnlineRooms
END IF

GO

create function DBA.CalcOccupiedOnlineRooms( in @Class integer ) 
returns integer
begin
  declare @result integer;
  declare @startDate date;
  set @startDate = bvrData1;
  set @result = 0;
  for F as Curs scroll cursor for
    select ReserveNo,FromDate,ToDate,RoomClass,Broi
      from v_OccupiedOnlineRooms
      where RoomClass = @Class do
    if(select DateIntersection(FromDate,ToDate,bvrData1,bvrData2)) > 0 then
      set @result = @result+Broi
    end if end for;
  /*
while @startDate < bvrData2 loop
end loop;
*/
  return @result
end