gpt4 book ai didi

java - SQL 服务器,HQL : How to compare SQL server datetime column field to date

转载 作者:行者123 更新时间:2023-11-29 06:30:03 24 4
gpt4 key购买 nike

我有以下 SQL 查询,我需要使它在 HQL 中工作,我尝试了几个解决方案,但没有一个有效。(数据库:SQL 服务器)

select t.createdTimeStamp FROM ServiceData t , UserInfo C where C.UserId = t.UserId and  CAST(t.createdTimeStamp AS DATE) = '2016-05-30'

我尝试在 HQL 中进行以下操作,但没有成功,(createdTimeStamp 是 sql server 中的 datetime 数据类型)

查询:

select t.createdTimeStamp FROM ServiceData t , UserInfo C where C.UserId = t.UserId and  CAST(t.createdTimeStamp AS DATE) = '2016-05-30'

错误:

org.hibernate.QueryException: Could not resolve requested type for CAST : DATE

任何有关如何使其发挥作用的建议都会有所帮助。

最佳答案

你必须按照下面的方式编写cast命令,然后它才会起作用

cast(t.createdTimeStamp as date)

所以“cast”、“as”和“date”都是小写的

关于java - SQL 服务器,HQL : How to compare SQL server datetime column field to date,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37698475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com