I have a Crystal report with one subreport. The main report and the subreport are linked to the same stored proc. The stored proc is basically the following at the end.
When I link the parameter fields from the main report to the subreport (so the user doesn't have to fill them in twice), I receive a query engine error message, Query Engine Error 42000 "incorrect syntax near ')'. If they are unlinked and I send the parameter field info twice, once for the main report and once for the subreport, I receive no error. The stored procedure works fine in query analyzer as well.
Anyone have any ideas on this error and how to fix it?
I'm using Crystal Reports 9 and SQL Server 2k.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE [dbo].generic(@BeginDate varchar(10),
@EndDate varchar(10),
@IDs varchar(50))
AS
set nocount on
DECLARE @SQLString NVARCHAR(4000)
SET @SQLString = N'SELECT *
FROM table1 As a
join table2 As b ON a.key = b.key
WHERE a.ID in (' + @IDs + ')
AND a.BeginDate >= convert(datetime,''' + @BeginDate + ''',102)+ ''00:00:00.000''
AND a.EndDate <= convert(datetime,''' + @EndDate + ''',102) + ''23:59:59.999''
GROUP BY b.Type
ORDER BY b.Type'
EXEC sp_executesql @SQLString
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
When I link the parameter fields from the main report to the subreport (so the user doesn't have to fill them in twice), I receive a query engine error message, Query Engine Error 42000 "incorrect syntax near ')'. If they are unlinked and I send the parameter field info twice, once for the main report and once for the subreport, I receive no error. The stored procedure works fine in query analyzer as well.
Anyone have any ideas on this error and how to fix it?
I'm using Crystal Reports 9 and SQL Server 2k.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE [dbo].generic(@BeginDate varchar(10),
@EndDate varchar(10),
@IDs varchar(50))
AS
set nocount on
DECLARE @SQLString NVARCHAR(4000)
SET @SQLString = N'SELECT *
FROM table1 As a
join table2 As b ON a.key = b.key
WHERE a.ID in (' + @IDs + ')
AND a.BeginDate >= convert(datetime,''' + @BeginDate + ''',102)+ ''00:00:00.000''
AND a.EndDate <= convert(datetime,''' + @EndDate + ''',102) + ''23:59:59.999''
GROUP BY b.Type
ORDER BY b.Type'
EXEC sp_executesql @SQLString
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO