Я изменил код, чтобы учесть ведущий ноль в месяце.
Declare @temp Table
(
project varchar(50),
month int,
year int
);
Insert Into @temp
(project, month, year)
Values ('abc', 2, 2017)
Insert Into @temp
(project, month, year)
Values ('xyz', 5, 2017)
Insert Into @temp
(project, month, year)
Values ('abc', 3, 2017)
Insert Into @temp
(project, month, year)
Values ('abc', 5, 2017)
Insert Into @temp
(project, month, year)
Values ('abc', 1, 2018)
Insert Into @temp
(project, month, year)
Values ('xxx', 5, 2010)
Insert Into @temp
(project, month, year)
Values ('xxx', 12, 2018)
Declare @FromYear int = 2010;
Declare @FromMonth int = 04;
Declare @ToYear int = 2018;
Declare @ToMonth int = 05;
Select *
From @temp
Where Convert(varchar, year) + right('00' + Convert(varchar, month), 2) Between '201004' and '201805'