需要更好的当前日期时间语法 [英] Need better current datetime syntax

查看:115
本文介绍了需要更好的当前日期时间语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我继承的当前/旧访问查询。需要检索过去一年案例日志。如何在Where子句中写出更好的当前日期?

This is current/old Access query I inherited.Need to retrieve the past year Case log. How can I write a better current date in Where clause?

    Select (ID,DateLog,TimeLog)
    From tblActiveCase
    WHERE (((DatePart("yyyy",[DateLog])) Between DatePart("yyyy",Now())-1 And           
     DatePart("yyyy",Now())))

- 我的新StoredProc

--My new StoredProc

    Select (ID,DateLog,TimeLog)
    From tblActiveCase
    WHERE DateLog <= DATEADD(YEAR, -1, GETDATE())

是否有更好的写入方式?

is there a better way to write it?

推荐答案

declare @date date
set @date = DATEADD(YEAR, -1, GETDATE())

    Select (ID,DateLog,TimeLog)
        From tblActiveCase
        WHERE DateLog >= @date

这篇关于需要更好的当前日期时间语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆