我一直在搜索此內容,但只獲得了指定日期的答案。從當前月份和上個月的特定日期之間選擇
我現在面臨的問題是:
返回所有比上月的20日和本月的20日之間的數據。
select name, data, activity from Table
where (year(data) = year(getdate()) and month(data) = month(getdate())-1 and day(data) >= 20) and (year(data) = year(getdate()) and month(data) = month(getdate()) and day(data) <= 20)
select name, data, activity from Table
where year(data) = year(getdate()) and month(data) >= month(getdate())-1 and day(data) >= 20
這最後一個會工作,但它不會返回當前月份的任何結果。
我已經嘗試了幾個where子句,但它只接受指定日期的接縫。有沒有辦法動態地做到這一點?
感謝
感謝@Gordon,但它接縫該公司正在使用SQL Server 2008,僅2012年來的有沒有什麼辦法來模擬2008年EOMONTH EOMONTH的?謝謝 –