如何在MSSQL中获得CURRENT_DATE? [英] How do I get CURRENT_DATE in MSSQL?

查看:55
本文介绍了如何在MSSQL中获得CURRENT_DATE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Hibernate中使用jpa3.o.我有一个命名查询:

I am using jpa 3.o with Hibernate. I have one named query:

SELECT COUNT(wt.id) FROM WPSTransaction wt WHERE wt.createdDate>= CURRENT_DATE

WPSTransaction是我的实体类,createdDate是我的类中的列之一.

WPSTransaction is my entity class and createdDate is one of the columns in my class.

在Mysql数据库中工作正常.但是,我要使用SQL Server 2012,并且SQL Server似乎没有编译 CURRENT_DATE 值.我尝试了 GETNOW() NOW()方法以及 current_date()方法和 CURRENT_TIMESTAMP 任何运气.

It's working fine in the Mysql Database. However, I'm moving to SQL Server 2012 and SQL server doesn't seem to compile the CURRENT_DATE value. I've tried GETNOW() and NOW() methods as well as current_date() method and CURRENT_TIMESTAMP without any luck.

推荐答案

MS SQL Server

MS SQL Server fails to conform to the standard here - it does not provide a current_date keyword.

您必须改为使用SQL Server特定的 GETDATE()函数,如链接的文档所示.

You must instead use the SQL-server specific GETDATE() function, as the document linked shows.

因为 current_date 是规范中的关键字,所以您不能只在MS SQL中创建用户定义的 current_date()函数并期望它能正常工作.因此,不幸的是,您在这里只能使用特定于数据库的代码.

Because current_date is a keyword in the spec, you can't just create a user-defined current_date() function in MS SQL and expect it to work the same. So unfortunately you're stuck with database-specific code here.

这篇关于如何在MSSQL中获得CURRENT_DATE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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