如何比较开始时间和结束与同一天的同一时间存在的事件事件的时间呢? [英] How to compare Starting time and End time of a event with existing events of same time on same day?
问题描述
我使用的MS SQL Server 2008的在这里,我需要一个事件的新输入的开始时间和结束时间与现有的事件时序进行比较。在数据库中,我需要检查新的开始时间和结束时间值和时间周期不应该与现有的/已经预订事件时序匹配。
我需要在数据库中的存储过程来检查这个条件,如果满足条件是那么只接受该事件。最好的例子就是会议厅预订。
SELECT @count = COUNT(事件ID)FROM TblEvent WHERE(('@STARTTIME'之间开始时间和结束时间)或( @ENDTIME'之间开始时间和结束时间));
IF @count = 0
开始
选择@count = COUNT(事件ID)FROM TblEvent WHERE(('@STARTTIME'<开始时间和'@ENDTIME'>结束时间));
结束
IF @count> 0
开始
选择事件是已经存在的时间点,请选择其他时间'为'信息';
结束
其他
开始
//添加查询保存中的事件DB //
选择以信息事件添加;
结束
请注意:
@STARTTIME =用户输入的开始时间,
@ENDTIME =用户输入的结束时间
I am using MS SQL server 2008. Here I need to compare the newly entered start time and End time of an event with the existing event timings. In the Database I need to check the new Starting time and End time values and the time Period should not match with the existing/ already booked event timings.
I need to check this condition in the Database stored procedure, if the condition is satisfied then only accept the event. Best example is Conference hall booking.
SELECT @count = COUNT (EventID) FROM TblEvent WHERE (('@STARTTIME' BETWEEN StartTime AND EndTime) or ('@ENDTIME' BETWEEN StartTime AND EndTime));
IF @count = 0
Begin
Select @count = COUNT (EventID) FROM TblEvent WHERE (('@STARTTIME' < StartTime and '@ENDTIME' > EndTime));
END
IF @count > 0
BEGIN
SELECT 'Event is Already Exists at that point of time please select another Time ' AS 'MESSAGE';
END
Else
BEGIN
//ADD QUERY TO SAVE THE THE EVENT IN DB//
SELECT 'Event is Added' AS 'MESSAGE';
END
NOTE:
@STARTTIME = USER ENTERED START TIME,
@ENDTIME =USER ENTERED END TIME
这篇关于如何比较开始时间和结束与同一天的同一时间存在的事件事件的时间呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!