IF (EXISTS (select proc_name from sysprocedure where LCase(proc_name)=LCase('IsTimeIntersect'))) THEN Drop function IsTimeIntersect END IF GO CREATE FUNCTION IsTimeIntersect(in WorkerId integer,in ForDate Date,in FromTime Time, in ToTime Time,in SpaN integer,in FromOfficeType integer) RETURNS integer BEGIN declare @TimeStep integer; declare @FromTime1 Time; declare @ToTime1 Time; set @TimeStep=(select IntStojnost from Registers where RegisterName='TimeStep'); for f as curs scroll cursor for select spaR.BeginTime as @BeginTime,spaR.TimeSteps as @TimeSteps from SpaReservations as spaR,SpaMedicalOffices as SpaMOff where spaR.BeginDate=ForDate and spaR.SpaWorker=WorkerId and spaR.ReservetionType<>3 and spaR.N<>SpaN and SpaMOff.N=spaR.MedicalOffice and ( (FromOfficeType=0) or ( (FromOfficeType=1) and (SpaMOff.AllowMultiGuests=0)) ) do set @FromTime1=@BeginTime; set @ToTime1=MINUTES(@FromTime1,@TimeSteps*@TimeStep); if ( ((FromTime>=@FromTime1) and (FromTime<@ToTime1)) or ( (ToTime>@FromTime1) and (ToTime<=@ToTime1)) or ( (FromTime<@FromTime1) and (ToTime>@ToTime1)) ) then RETURN(1); end if; end for; RETURN(0); END