You can try this query.
create table #test(id int,date datetime);
insert into #test values
(1,'2023-01-06'),
(2,'2023-02-01'),
(3,'2023-02-12'),
(4,'2023-02-15'),
(5,'2023-03-07'),
(6,'2022-12-10'),
(7,'2022-12-20');
select * from #test
where (month(date) = month(getdate()) - 1 and year(date) = year(getdate()))
or (year(date) = year(getdate()) - 1 and month(date) = 12 and month(getdate()) = 1);
Output:
It will find data for February 2023.
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.