这是我继承的当前/旧的Access查询。需要检索过去一年的案例日志。如何在Where子句中写出更好的当前日期?
Select (ID,DateLog,TimeLog)
From tblActiveCase
WHERE (((DatePart("yyyy",[DateLog])) Between DatePart("yyyy",Now())-1 And
DatePart("yyyy",Now())))
- 我的新StoredProc
Select (ID,DateLog,TimeLog)
From tblActiveCase
WHERE DateLog <= DATEADD(YEAR, -1, GETDATE())
有没有更好的方式来写它?
答案 0 :(得分:0)
declare @date date
set @date = DATEADD(YEAR, -1, GETDATE())
Select (ID,DateLog,TimeLog)
From tblActiveCase
WHERE DateLog >= @date