find records from previous x days?

前端 未结 4 579
走了就别回头了
走了就别回头了 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条回答
  •  旧时难觅i
    2021-01-03 23:41

    Something like this?

      CREATE PROC GetSomeHistory
    
       @NumDaysPrevious   int
    
       AS
       BEGIN
           SELECT * FROM MyTable
           WHERE RequestDate BETWEEN DATEADD(dd, -1 * @NumDaysPrevious, getdate())
                                 AND getdate();
       END
    
       ......
    
       EXEC GetSomeHistory 55;
    

提交回复
热议问题