find records from previous x days?

前端 未结 4 586
走了就别回头了
走了就别回头了 2021-01-03 23:18

How can I come up with a stored procedure that selects results for past 30 days?

where MONTH(RequestDate) > 6 and DAY(RequestDate) >= 10 
and MONTH(Req         


        
4条回答
  •  臣服心动
    2021-01-03 23:45

    Are you looking for last 30 days or last month? To find start and end of each month ("generic" as your comment says), use:

    select  dateadd(month,datediff(month,0,getdate()),0), 
        dateadd(mm,datediff(mm,-1,getdate()),-1)
    

提交回复
热议问题