How to get the last month data and month to date data

后端 未结 4 1274
小鲜肉
小鲜肉 2020-12-28 21:50

Need help in writing the query to get the last month data as well as month to date data.

If today\'s date is Mar 23 2011, I need to retrieve the data from last month

4条回答
  •  情书的邮戳
    2020-12-28 22:44

    Select Column1, Column2 From Table1
    Where DateColumn <= GetDate() AND 
    DateColumn >= DATEADD(dd, - (DAY(DATEADD(mm, 1, GetDate())) - 1), DATEADD(mm, - 1, GetDate()))
    

    Edit: +1 to Russel Steen. I was posting mine before I knew he had posted.

提交回复
热议问题