我需要当前月份的动态日期,这将自动更新每个月,而不是写完整的日期(在'5/1/2022'和'5/31/2022'之间)。我当前的查询
Select TDate, sum(CustSales) As 'Total Sales'
From SalesTra
Where TDate between '5/1/2022' and '5/31/2022'
Group by TDate
试试这个:
Select TDate, sum(CustSales) As 'Total Sales'
From SalesTra
Where TDate between (DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)) and (DATEADD(month, ((YEAR(GETDATE()) - 1900) * 12) + MONTH(GETDATE()), -1))
Group by TDate