我一直在寻找几天来解决我的 Fullcalender 上重复事件的问题。我最简单的方法可能是根据存储在表中的数据生成重复日期。
我过去没有使用过 CTE 查询。我需要的是为天生成重复日期示例
每个星期一和星期四,我们都会在办公室举行项目会议。在这种情况下,我将设置开始日期 = 2012-06-04 结束日期 = 2012-06-31
现在我想生成 SQL 查询,它将显示从 2012 年 6 月 4 日到 2012 年 8 月 31 日的所有日期,基于它们是否重复发生
EventID Date Title
1 2012-06-04 Project Meeting
1 2012-06-07 Project Meeting
1 2012-06-11 Project Meeting
1 2012-06-14 Project Meeting
1 2012-06-18 Project Meeting
1 2012-06-21 Project Meeting
1 2012-06-25 Project Meeting
1 2012-06-18 Project Meeting
2 2012-05-13 Meeting With Client
3 2012-06-25 Event 3
我能够理解我如何能够做到这一点,我将不胜感激这方面的帮助或指出类似的例子。如果我能够正确生成此数据,那么我可以将这些日期与 eventTitle 一起发送到 FullCalender 控件以显示事件日历,如下面的示例所示http://arshaw.com/fullcalendar/
如果有人愿意帮助他可以从下面的 sql 创建表和示例数据。这是 MS SQL SERVER 2008 r2 兼容的,因为我使用了仅受 MS SQL 2008 支持的数据类型
带有数据的架构
/****** Object: Table [dbo].[EventCalender] Script Date: 05/24/2012 20:18:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[EventCalender](
[EventID] [int] IDENTITY(1,1) NOT NULL,
[EventTitle] [nvarchar](900) NULL,
[EventDetails] [nvarchar](max) NULL,
[EventStartDate] [date] NOT NULL,
[EventEndDate] [date] NULL,
[EventStartTime] [time](0) NULL,
[EventEndTime] [time](0) NULL,
[EventRecurring] [bit] NULL,
[EventEnumDays] [varchar](50) NULL,
[EventBlockDate] [bit] NULL,
[EventVisibleOnWebsite] [bit] NULL,
[EventActive] [bit] NULL,
[EventType] [nvarchar](200) NULL,
[LanguageID] [int] NOT NULL,
[EventCreatedOn] [date] NULL,
[EventShowTime] [bit] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[EventCalender] ON
INSERT [dbo].[EventCalender] ([EventID], [EventTitle], [EventDetails], [EventStartDate], [EventEndDate], [EventStartTime], [EventEndTime], [EventRecurring], [EventEnumDays], [EventBlockDate], [EventVisibleOnWebsite], [EventActive], [EventType], [LanguageID], [EventCreatedOn], [EventShowTime]) VALUES (1, N'Project Meeting', N'Every Monday, Thrusday', CAST(0xC1350B00 AS Date), CAST(0x19360B00 AS Date), CAST(0x00A08C0000000000 AS Time), CAST(0x00B8A10000000000 AS Time), 1, N'2,5,7', 0, 0, 1, N'EVENT', 1, CAST(0xB6350B00 AS Date), NULL)
INSERT [dbo].[EventCalender] ([EventID], [EventTitle], [EventDetails], [EventStartDate], [EventEndDate], [EventStartTime], [EventEndTime], [EventRecurring], [EventEnumDays], [EventBlockDate], [EventVisibleOnWebsite], [EventActive], [EventType], [LanguageID], [EventCreatedOn], [EventShowTime]) VALUES (2, N'Meeting With Client', N'Event Details 2', CAST(0xBA350B00 AS Date), CAST(0xBA350B00 AS Date), NULL, NULL, 0, NULL, 0, 0, 1, N'EVENT', 1, CAST(0xB6350B00 AS Date), NULL)
INSERT [dbo].[EventCalender] ([EventID], [EventTitle], [EventDetails], [EventStartDate], [EventEndDate], [EventStartTime], [EventEndTime], [EventRecurring], [EventEnumDays], [EventBlockDate], [EventVisibleOnWebsite], [EventActive], [EventType], [LanguageID], [EventCreatedOn], [EventShowTime]) VALUES (3, N'Event 3', N'Event Details 3', CAST(0xAB350B00 AS Date), CAST(0xAB350B00 AS Date), NULL, NULL, 0, NULL, 0, 0, 0, N'EVENT', 1, CAST(0xB6350B00 AS Date), 0)
INSERT [dbo].[EventCalender] ([EventID], [EventTitle], [EventDetails], [EventStartDate], [EventEndDate], [EventStartTime], [EventEndTime], [EventRecurring], [EventEnumDays], [EventBlockDate], [EventVisibleOnWebsite], [EventActive], [EventType], [LanguageID], [EventCreatedOn], [EventShowTime]) VALUES (5, N'Weekly Meeting', N'Weekly Event', CAST(0xA3350B00 AS Date), CAST(0x01380B00 AS Date), CAST(0x00D0B60000000000 AS Time), NULL, 1, N'2,', 0, 1, 1, N'ACTIVITY', 2, NULL, 0)
SET IDENTITY_INSERT [dbo].[EventCalender] OFF
/****** Object: Default [DF_EventCalender_EventEndDate] Script Date: 05/24/2012 20:18:00 ******/
ALTER TABLE [dbo].[EventCalender] ADD CONSTRAINT [DF_EventCalender_EventEndDate] DEFAULT (NULL) FOR [EventEndDate]
GO
/****** Object: Default [DF_EventCalender_EventStartTime] Script Date: 05/24/2012 20:18:00 ******/
ALTER TABLE [dbo].[EventCalender] ADD CONSTRAINT [DF_EventCalender_EventStartTime] DEFAULT (NULL) FOR [EventStartTime]
GO
/****** Object: Default [DF_EventCalender_EventEndTime] Script Date: 05/24/2012 20:18:00 ******/
ALTER TABLE [dbo].[EventCalender] ADD CONSTRAINT [DF_EventCalender_EventEndTime] DEFAULT (NULL) FOR [EventEndTime]
GO
/****** Object: Default [DF_EventCalender_EventRecurring] Script Date: 05/24/2012 20:18:00 ******/
ALTER TABLE [dbo].[EventCalender] ADD CONSTRAINT [DF_EventCalender_EventRecurring] DEFAULT ((0)) FOR [EventRecurring]
GO
/****** Object: Default [DF_EventCalender_EventEnumDays] Script Date: 05/24/2012 20:18:00 ******/
ALTER TABLE [dbo].[EventCalender] ADD CONSTRAINT [DF_EventCalender_EventEnumDays] DEFAULT (NULL) FOR [EventEnumDays]
GO
/****** Object: Default [DF_EventCalender_EventBlockDate] Script Date: 05/24/2012 20:18:00 ******/
ALTER TABLE [dbo].[EventCalender] ADD CONSTRAINT [DF_EventCalender_EventBlockDate] DEFAULT ((0)) FOR [EventBlockDate]
GO
/****** Object: Default [DF_EventCalender_EventVisibleOnWebsite] Script Date: 05/24/2012 20:18:00 ******/
ALTER TABLE [dbo].[EventCalender] ADD CONSTRAINT [DF_EventCalender_EventVisibleOnWebsite] DEFAULT ((0)) FOR [EventVisibleOnWebsite]
GO
/****** Object: Default [DF_EventCalender_EventActive] Script Date: 05/24/2012 20:18:00 ******/
ALTER TABLE [dbo].[EventCalender] ADD CONSTRAINT [DF_EventCalender_EventActive] DEFAULT ((0)) FOR [EventActive]
GO
/****** Object: Default [DF_EventCalender_EventShowTime] Script Date: 05/24/2012 20:18:00 ******/
ALTER TABLE [dbo].[EventCalender] ADD CONSTRAINT [DF_EventCalender_EventShowTime] DEFAULT ((0)) FOR [EventShowTime]
GO