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\".
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}
To avoid the error message "The datepart hour is not supported by date function dateadd for data type date" it's sometimes necessary to do a double cast after getting the current time (firstly to cast it as date to get rid of the time, and then back to datetime to enable adding time to it). For example, if you need 11:00 today, use:
DATEADD(hour, 11, cast(cast(getdate() as date) as datetime))