【问题标题】:Is it possible to have a sub-select in a HQL dateAdd function?是否可以在 HQL dateAdd 函数中进行子选择?
【发布时间】:2011-07-20 03:31:47
【问题描述】:

我在 Hibernate 3 中使用 HQL dateAdd 函数时遇到了一些问题。

在下面的代码中,我想获取所有 lastTimeDate 大于最大截止日期加 3 个月的事项。

<cfoutput>
        <cfsavecontent variable="hSql">
            from matter as m
            where m.lastTimeDate < dateAdd(month, 3, (select max(d.cutOffDate) from deadline as d))
        </cfsavecontent>
    </cfoutput>

    <cfset var awMatters = ormExecuteQuery(hSql) />

但是,当我执行查询时,我收到以下错误:

java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]The dateadd function requires 3 argument(s).

我错过了什么吗?我的 dateAdd 函数中肯定有 3 个参数。

我正在使用 Coldfusion 9 (ORM) 和 MSSql 2005 服务器。

谢谢

【问题讨论】:

    标签: hibernate orm coldfusion hql


    【解决方案1】:

    先做select max(d.cutOffDate) from deadline

    然后ormExecuteQuery("from matter where lastTimeDate &lt; ?", [dateAdd('m', 3, cutOffDate)])

    【讨论】:

      【解决方案2】:

      别名是否正确?你介意试试这个吗?

       <cfsavecontent variable="hSql">
                  from matter as m
                  where m.lastTimeDate < dateAdd(month, 3, (select max(cutOffDate) from deadline))
              </cfsavecontent>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-20
        • 1970-01-01
        • 2017-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-18
        • 1970-01-01
        相关资源
        最近更新 更多