[英]Bringing in data for current month and year
I'm trying to bring in data for the current month (5/1-5/31) and do the same for every month coming forward.我正在尝试引入当月(5/1-5/31)的数据,并为接下来的每个月做同样的事情。 Where I use the following code, it's not working.
在我使用以下代码的地方,它不起作用。 If I change it to >= it brings, in data all the way from 2016. Any ideas what I'm doing wrong?
如果我将其更改为 >= 它会带来从 2016 年开始的数据。任何想法我做错了什么?
WHERE [20200512 Daily Deposits].[Date] = MONTH(getdate())
AND [20200512 Daily Deposits].[Date] = YEAR(getdate())
Assuming you are using SQL Server:假设您使用的是 SQL 服务器:
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))
Assuming that the .[Date]
column is actual a date type then you can just do..假设
.[Date]
列是实际的日期类型,那么您可以这样做..
WHERE MONTH([20200512 Daily Deposits].[Date]) = MONTH(getdate())
AND YEAR([20200512 Daily Deposits].[Date]) = YEAR(getdate())
If they are not date data types then please edit your question and show some sample data with the data types explained.如果它们不是日期数据类型,那么请编辑您的问题并显示一些示例数据以及解释的数据类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.