Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Monthly events calendar
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00779571
Message ID:
00779586
Views:
12
This message has been marked as a message which has helped to the initial question of the thread.
>>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. :)
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform