IF (EXISTS(Select * from sys.sysprocedure where LCase(proc_name) = LCase('CheckIntersectionOfRoomStatuses'))) THEN Drop procedure CheckIntersectionOfRoomStatuses END IF GO create procedure CheckIntersectionOfRoomStatuses(in @StartDate date, in @EndDate date, in @Room integer, in @Status integer, in @Komentar varchar(250)) begin declare @TempStartDate date; declare @TempEndDate date; for f as curs scroll cursor for select N as @N,StartDate as @SDate,EndDate as @EDate from RoomStatusForPeriod where NRoom = @Room and @StartDate <= EndDate and @EndDate >= StartDate do if (@EDate > @EndDate) then if (@SDate > @StartDate) then set @TempEndDate = @EDate else set @TempEndDate = dateadd(day,-1,@StartDate) end if else set @TempEndDate = dateadd(day,-1,@StartDate) end if; if (@SDate < @StartDate) then set @TempStartDate = @SDate else set @TempStartDate = DateAdd(day,1,@EndDate) end if; if (@TempEndDate < @TempStartDate) then delete from RoomStatusForPeriod where N = @N else update RoomStatusForPeriod set StartDate = @TempStartDate, EndDate = @TempEndDate where N=@N; end if; end for; insert into RoomStatusForPeriod (NRoom,NStatus,StartDate,EndDate,Komentar) values (@Room,@Status,@StartDate,@EndDate,@Komentar) end //[v.1 - 07.03.2008] - Maria - funkcia, koiato proveriava za zastupvashti se periodi za status na staia