我正在尝试编写一个查询以根据以下内容选择记录:
- 它们应该属于特定类别
它们应该在开始日期和结束日期之间。
我有这样的记录:
EventId| EventName| Event_Category| Event_StartDate| Event_EndDate| 1 | aaa | 4 | 2014-06-10 | 2014-06-15 | 2 | bbb | 5 | 2014-06-10 | 2014-06-15 | 3 | ccc | 6 | 2014-06-10 | 2014-07-11 | 4 | ddd | 5 | 2014-06-01 | 2014-07-10 | 5 | eee | 5 | 2014-06-10 | 2014-06-014 |
存储过程:
create proc usp_filterevnts @Categoryid int, @StartDate date, @EndDate date as begin select * from Events Where Event_Category=@Categoryid and ( Event_Startdate>@StartDate and Event_Enddate<@EndDate ) end
如果我执行 sp 作为
exec usp_filterevnts 5,'2014-06-09','2014-06-16'
它应该显示第 5 类记录的记录,其开始日期和结束日期在 '2014-06-09' 和 '2014-06-16' 之间......即第 2 条记录,第 5 条记录..
我的存储过程对此是否正确?