ID 人员ID 起始日期 终止日期 办事处 调整原因
1 1001 2010-1-1 2010-3-31 南京 业务需要
2 1001 2010-4-1 至现在 上海 <null>
3 1002 2010-2-1 2010-3-28 广州 不适应
4 1002 2010-3-29 至现在 珠海 <null>
现在有个需求:
比如:我输入:2010-3-1 -----2010-3-31
得到的统计表是:
人员ID 调整日期 调整描述 调整原因
1002 2010-3-28 广州----珠海 不适应
1001 2010-3-31 南京----上海 业务需要
通过SQL语句实现.
SQL code:
create proc aaa @stime datetime,@etime datetime
select * from tb where 起始日期>@stime and 终止日期<@etime
看错了,不好意思
你输入的时间是在哪里输入?作为存储过程的参数还是直接放入sql语句中
where 终止日期 between '2010-3-1' and '2010-3-31'
SQL code:
create table #test(ID int,人员ID int,起始日期 datetime,终止日期 datetime,办事处 varchar(20),调整原因 varchar(20))
insert #test select 1 ,1001 ,'2010-1-1','2010-3-31', '南京', '业务需要'
insert #test select 2 ,1001 ,'2010-4-1',getdate(), '上海', null
insert #test select 3 ,1002 ,'2010-2-1',' 2010-3-28',