Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Function Performance Issue
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01258360
Message ID:
01258487
Vues:
15
Sergey and Borislav

Thanks for you input. Even with it as part of the original query, the delay was still there. Also, using it as a function, provides the ability to "reuse that code" in other queries, making maintenance easier.

I did work out a solution as provided below which brought the performance back down to with 1-3 seconds depending on the parameters:
CREATE FUNCTION ctFun_RoomConflict  (@RoomID int, @iLength int, @StartTime datetime )  
RETURNS int as 
BEGIN 
        DECLARE @returnValue int
        DECLARE @EndTime datetime
        SET @EndTime = dateadd(mi,@iLength,@StartTime)
        /*
	Created variables @RangeFrom and @RangeTo
        */
        DECLARE @RangeFrom datetime
        DECLARE @RangeTo datetime
        SET @RangeFrom=convert(varchar(10),@StartTime,110)+' 00:00:00'
        SET @RangeTo    =convert(varchar(10),@StartTime,110)+' 23:59:59'
        /* Modified the query to use a derived query to first get all the records for just
            the selected date @RangeFrom and @RangeTo, this limited kept SQL
            from looking at all the records in the table, then applied my where clause
            for the @StartTime/@EndTime to the results of the derived query
        */
        select  @returnValue=
	  (select count(det.meetingnumber) from 
	        ( select meetingnumber,begintime,endtime from dbo.meetings 
	   	where  iscancelled=0 and roomid = @RoomID and
		begintime between @RangeFrom and @RangeTo)det
	  where @StartTime between Begintime and EndTime or @EndTime between BeginTime and EndTime )

      return (@returnValue)

END
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform