【发布时间】:2014-10-07 09:22:34
【问题描述】:
我已经编写了过去三个月的 SQL 来选择用户数据,但我认为目前它每天都会更新。
我想更改它,以便现在是 10 月,它不会计算 10 月的数据,而是计算 7 月到 9 月的数据,当我们进入 11 月时更改为 8 月到 10 月
这是我目前得到的SQL:
declare @Today datetime
declare @Category varchar(40)
set @Today = dbo.udf_DateOnly(GETDATE())
set @Category = 'Doctors active last three months updated'
declare @last3monthsnew datetime
set @last3monthsnew=dateadd(m,-3,dbo.udf_DateOnly(GETDATE()))
delete from LiveStatus_tbl where Category = @Category
select @Category, count(distinct U.userid)
from UserValidUKDoctor_vw U
WHERE LastLoggedIn >= @last3monthsnew
我将如何编辑它来做到这一点?
【问题讨论】:
标签: sql sql-server reporting