CREATE FUNCTION ctFun_RoomConflictA (@RoomID int, @iLength int, @StartTime datetime ) RETURNS int as BEGIN Declare @returnValue int select @returnValue= (select count(meetingnumber) from dbo.meetings where (begintime between @StartTime and dateadd(mi,@iLength,@StartTime) or endtime between @StartTime and dateadd(mi,@iLength,@StartTime) or @StartTime between begintime and endtime or dateadd(mi,@ilength,@StartTime) between begintime and endtime) and iscancelled=0 and roomid = @RoomID ) return (@returnValue) ENDThanks