CREATE TABLE [dbo].t_date (
[name] nvarchar(10) NOT NULL,
[入职时间] Datetime NOT NULL,
) ON [PRIMARY]
GO
insert into t_date ( name , 入职时间 ) values ('a1','2016-4-10')
insert into t_date ( name , 入职时间 ) values ('a2','2016-4-11')
insert into t_date ( name , 入职时间 ) values ('a3','2016-4-12')
insert into t_date ( name , 入职时间 ) values ('a4','2016-4-13')
insert into t_date ( name , 入职时间 ) values ('a5','2016-4-14')
insert into t_date ( name , 入职时间 ) values ('a6','2016-4-15')
insert into t_date ( name , 入职时间 ) values ('a7','2016-4-16')
insert into t_date ( name , 入职时间 ) values ('a8','2016-4-17')
insert into t_date ( name , 入职时间 ) values ('a9','2016-4-18')
insert into t_date ( name , 入职时间 ) values ('a10','2016-4-19')
insert into t_date ( name , 入职时间 ) values ('a11','2016-4-20')
insert into t_date ( name , 入职时间 ) values ('a12','2016-4-21')
insert into t_date ( name , 入职时间 ) values ('a13','2016-4-22')
insert into t_date ( name , 入职时间 ) values ('a14','2016-4-23')
insert into t_date ( name , 入职时间 ) values ('a15','2016-4-24')
insert into t_date ( name , 入职时间 ) values ('a16','2016-5-10')
insert into t_date ( name , 入职时间 ) values ('a17','2016-5-11')
insert into t_date ( name , 入职时间 ) values ('a18','2016-5-12')
insert into t_date ( name , 入职时间 ) values ('a19','2016-5-13')
insert into t_date ( name , 入职时间 ) values ('a20','2016-5-14')
insert into t_date ( name , 入职时间 ) values ('a21','2016-5-15')
insert into t_date ( name , 入职时间 ) values ('a22','2016-5-16')
insert into t_date ( name , 入职时间 ) values ('a23','2016-5-17')
insert into t_date ( name , 入职时间 ) values ('a24','2016-5-18')
insert into t_date ( name , 入职时间 ) values ('a25','2016-5-19')
insert into t_date ( name , 入职时间 ) values ('a26','2016-5-20')
insert into t_date ( name , 入职时间 ) values ('a27','2016-5-21')
insert into t_date ( name , 入职时间 ) values ('a28','2016-5-22')
insert into t_date ( name , 入职时间 ) values ('a29','2016-5-23')
insert into t_date ( name , 入职时间 ) values ('a30','2016-5-24')
insert into t_date ( name , 入职时间 ) values ('a31','2016-6-10')
insert into t_date ( name , 入职时间 ) values ('a32','2016-6-11')
insert into t_date ( name , 入职时间 ) values ('a33','2016-6-12')
insert into t_date ( name , 入职时间 ) values ('a34','2016-6-13')
insert into t_date ( name , 入职时间 ) values ('a35','2016-6-14')
insert into t_date ( name , 入职时间 ) values ('a36','2016-6-15')
insert into t_date ( name , 入职时间 ) values ('a37','2016-6-16')
insert into t_date ( name , 入职时间 ) values ('a38','2016-6-17')
insert into t_date ( name , 入职时间 ) values ('a39','2016-6-18')
insert into t_date ( name , 入职时间 ) values ('a40','2016-6-19')
insert into t_date ( name , 入职时间 ) values ('a41','2016-6-20')
insert into t_date ( name , 入职时间 ) values ('a42','2016-6-21')
insert into t_date ( name , 入职时间 ) values ('a43','2016-6-22')
insert into t_date ( name , 入职时间 ) values ('a44','2016-6-23')
insert into t_date ( name , 入职时间 ) values ('a45','2016-6-24')
GO
Create Proc DateBetweens @s nvarchar(7),@e nvarchar(7)
AS
BEGIN
Select 入职时间 ,
YEAR( case when DAY(入职时间)<15 THEN DateAdd(M,-1,入职时间) else 入职时间 end ) * 100 + MONTH ( case when DAY(入职时间)<15 THEN DateAdd(M,-1,入职时间) else 入职时间 end ) as 月份,
name from T_Date
Where 入职时间 >= DATEADD(M,-1,@s + '-15') AND 入职时间 < @e + '-14'
END
GO
DateBetweens '2016-05','2016-10'