exec sp_executesql error 'Incorrect syntax near 1' when using datetime parameter

Posted by anne78 on Stack Overflow See other posts from Stack Overflow or by anne78
Published on 2010-04-30T07:09:08Z Indexed on 2010/04/30 7:17 UTC
Read the original article Hit count: 127

Filed under:
|

I have a Ssrs report which sends the following text to the database :

EXEC ( 'DECLARE @TeamIds as TeamIdTableType ' + @Teams + ' EXEC rpt.DWTypeOfSicknessByCategoryReport @TeamIds , ' + @DateFrom + ', ' + @DateTo + ', ' + @InputRankGroups + ', ' + @SubCategories )

When I view this in profiler it interprets this as :

exec sp_executesql N'EXEC ( ''DECLARE @TeamIds as TeamIdTableType '' + @Teams + '' EXEC rpt.DWTypeOfSicknessByCategoryAndEmployeeDetailsReport @TeamIds, '' + @DateFrom + '', '' + @DateTo + '', '' + @InputRankGroups + '', '' + @SubCategories )',N'@Teams nvarchar(34),@DateFrom datetime,@DateTo datetime,@InputRankGroups varchar(1),@SubCategories bit',@Teams=N'INSERT INTO @TeamIds VALUES (5); ',@DateFrom='2010-02-01 00:00:00',@DateTo='2010-04-30 00:00:00',@InputRankGroups=N'1',@SubCategories=1

When this sql runs it errors, on the dates. I have tried changing the format of the date but it does not help. If I remove the dates it works fine.

Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about datetime

Related posts about sql-server