I’m getting a data type conflict error when trying to run my report in JasperReports. The error message displays ‘Operand type clash: date is incompatible with int’ yet the same SQL query executes perfectly when I run it directly in SQL Server Management Studio.
net.sf.jasperreports.engine.JRException: Error executing SQL statement for : Monthly_Sales_Report
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Operand type clash: date is incompatible with int
Here’s how I’ve set up my parameter and the query:
<parameter name="ReportDate" isForPrompting="true" class="java.util.Date">
<defaultValueExpression><![CDATA[new Date(System.currentTimeMillis())]]></defaultValueExpression>
</parameter>
<queryString><![CDATA[
declare @begin_date as datetime;
declare @final_date as datetime;
declare @location_group as nvarchar(50);
set @begin_date = $P{ReportDate}-1;
set @final_date = $P{ReportDate};
set @location_group = 'REGION1';
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[#temp_orders]') AND type in (N'U'))
DROP TABLE [dbo].[#temp_orders]
create table #temp_orders (location_id uniqueidentifier, order_type_id int, subtotal_amount float, tax_amount float, total_amount float, item_category_id int);
insert into #temp_orders (location_id, order_type_id, subtotal_amount, tax_amount, total_amount, item_category_id)
select o.location_id, order_type_id, od.subtotal_amount, od.tax_amount, od.total_amount, od.item_category_id
from order_details od
inner join orders o on od.order_id = o.order_id
where o.order_date >= @begin_date and o.order_date < @final_date
select
loc.location_code as [Location],
@begin_date as [Period],
(select count(*) from orders o where o.order_date >= @begin_date and o.order_date < @final_date and o.location_id = loc.location_id) as [Total Orders],
(select isnull(sum(subtotal_amount),0) from #temp_orders t where t.location_id = loc.location_id and t.order_type_id = 1) as [Service Revenue]
from locations loc
where loc.status = 'Active'
order by loc.location_code
drop table #temp_orders
]]></queryString>
It’s puzzling because this SQL runs fine in SSMS. Has anyone faced a similar issue with date parameters in JasperReports? What might be causing this data type mismatch?