The datepart hour is not supported by date function dateadd for data type date

前端 未结 2 978
傲寒
傲寒 2021-02-13 04:37

While I am running the following query in jasper reports, I got the exception. \"net.sf.jasperreports.engine.JRException: Error executing SQL statement for : Activity_Summary\".

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-13 05:27

    This happens because your input parameters are of the data type date, and not datetime. Because the date data type's precision only runs to day level, not anything smaller.

    For example, this will fail in SQL Server:

    declare @Start as date = '20130201'
    declare @End as date = '20130210'
    declare @startdate as datetime;
    declare @enddate as datetime;
    set @startdate = DATEADD(hh, +0, @Start)
    set @enddate = DATEADD(hh, +0, @End)
    

    While this will work:

    declare @Start as datetime = '20130201'
    declare @End as datetime = '20130210'
    declare @startdate as datetime;
    declare @enddate as datetime;
    set @startdate = DATEADD(hh, +0, @Start)
    set @enddate = DATEADD(hh, +0, @End)
    

    If you ensure that the parameters supplied by your application (below) are of type datetime and not date, you should get rid of the error.

    $P{StartDate}
    $P{EndDate}
    

提交回复
热议问题