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:
00779572
Vues:
13
This message has been marked as the solution to the initial question of the thread.
You can try something like
DECLARE @FirstOfTheMonth datetime
DECLARE @LastOfTheMonth datetime

SET @FirstOfTheMonth = '2003/04/01'
SET @LastOfTheMonth = DATEADD(day,-1, DATEADD(month, 1, @FirstOfTheMonth))

SELECT 
		SUM( CASE WHEN StartDate <= @FirstOfTheMonth + 0 And EndDate >= @FirstOfTheMonth + 0
				THEN 1 ELSE 0 END ) AS day01
		SUM( CASE WHEN StartDate <= @FirstOfTheMonth + 1 And EndDate >= @FirstOfTheMonth + 1
				THEN 1 ELSE 0 END ) AS day02
...

		SUM( CASE WHEN StartDate <= @FirstOfTheMonth + 27 And EndDate >= @FirstOfTheMonth + 27
				THEN 1 ELSE 0 END ) AS day28

		SUM( CASE WHEN StartDate <= @FirstOfTheMonth + 28 And EndDate >= @FirstOfTheMonth + 28
					And @FirstOfTheMonth + 28 <= @LastOfTheMonth
				THEN 1 ELSE 0 END ) AS day29
...
>Hi everybody,
>
>Bellow is a problem, I found interesting, and would appreciate your input.
>============
>I have a table with events that has an Event Description, a start date and an end date and some other fields.
>When i'm showing the current month's calendar, i want to display the summary of the events for each day, but without running a query for every day.
>For exampe when i'm showing the 1st day of the month, i've got to summarize all the events (from the events table) that are active for the particular day.
>
>------------------------------------
>| 1  | 2  | 3  | 4  | 5  | 6  | 7  |
>|(2) |(7) |    |    |(9) |    |    |
>------------------------------------
>| 8  | 9  | 10 | 11 | 12 | 13 | 14 |
>|(2) |(7) |    |    |(9) |    |    |
>------------------------------------
>| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
>|    |    |    |(14)|(9) |(3) |    |
>------------------------------------
>| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
>|    |    |(11)|    |    |(12)|    |
>------------------------------------
>| 29 | 30 | 31 |    |    |    |    |
>|    |(4) |    |    |    |    |    |
>------------------------------------
>
>Thanks in advance.
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform