SQL - View Event Data for Current Quarter

advertisements

I have a course calendar events table as follows (showing only a few records for simplicity):

calendarItemID   classID   startDate   startTime   endTime
----------------------------------------------------------
1                1         2011-11-24  7pm         9pm
2                2         2011-11-02  7pm         9pm
3                1         2011-11-25  7pm         9pm

I need a query that returns courses for the UPCOMING QUARTER (not the current quarter). Is there a SQL function that can help and/or is this a case of working out the dates in the current quarter and seeing if StartDate fits within those dates. I'm looking for the most elegant way if possible.

Thanks in advance! Paul


Straightforward, but slow approach :

WHERE DATEPART(qq,startDate) = DATEADD(qq, 1,GETDATE()) AND YEAR(startDate) =
YEAR(DATEADD(qq, 1,GETDATE()))

By slow I mean that even if you have an index on (startDate) it won't be used.

The better solution is to get start_date and end_date for the next quarter. I can see a number of ways to do so. For instance, you can create 2 scalar UDF that returns start_date and end_date respectively. You can also create 1 table-valued function that returns 1 row with 2 columns and then join it. Finally, you can just create a lookup table and manually enter start/end date for next couple of years.