Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Monthly events calendar
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00779571
Message ID:
00779610
Vues:
9
>>>>I realized that my comment about SQL Server using or not any index to optimize query is irrelevant for '@FirstOfTheMonth + 0 BETWEEN StartDate And EndDate' expression because those checks performed on the column level so they will not be used to optimeze query anyway. You can add one more condition to your query to speed it up
WHERE (StartDate BETWEEN @FirstOfTheMonth And @LastOfTheMonth
>>  OR EndDate BETWEEN @FirstOfTheMonth And @LastOfTheMonth )
>>>
>>>Why it's an OR condition (should be AND, I think). Should it be for all days, right? Where should I put it? Can you give me the whole query again, please. I have hard time thinking this late at night...
>>
>>Yes, it has to be 'OR' because event could start in one month and end in another. If you change it to 'AND' you'll get only events that start and end in the current month. You will put this WHERE clause right after FROM clause, as usual. :)
>
>Thanks again. I guess, I can not stay awake any longer... I just had to send something by e-mail and then can go to sleep...

Opps! They both are incorrect, because with 'And' it will skip events that start before current month and end someday after. It should be
WHERE ( @FirstOfTheMonth BETWEEN StartDate And EndDate 
	OR @LastOfTheMonth  BETWEEN StartDate And EndDate )
which brings back question if it's optimizable or not.
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform