引入当前月份和年份的数据

问题描述 投票:0回答:1

我正在尝试引入当月(5 / 1-5 / 31)的数据,并在以后的每个月都这样做。在使用以下代码的地方,它不起作用。如果我将其更改为> =,它将带来2016年以来的所有数据。有什么想法我做错了吗?

 WHERE [20200512 Daily Deposits].[Date] = MONTH(getdate()) and [20200512 Daily Deposits].[Date] = YEAR(getdate())
sql datetime ssrs-2008
1个回答
0
投票

假设您正在使用SQL Server:

where [20200512 Daily Deposits].[Date] >= datefromparts(year(getdate(), month(getdate(), 1) and
      [20200512 Daily Deposits].[Date] < dateadd(month, 1, datefromparts(year(getdate(), month(getdate(), 1))
© www.soinside.com 2019 - 2024. All rights reserved.