Hi,
I have the SSRS report to pass the @StartDate and @EndDate into the dynamic query but keep getting an error. I have from the query and need to use the dynamic, but i am only provided you the simple one to easy to understand it.
Thanks
declare @query nvarchar(max)
declare @StartDate datetime
declare @EndDate datetime
set @StartDate = '2018-10-22'
set @EndDate ='2018-10-22'
set @query = '
select *
from ttisfc001491
where t_cmdt between convert(varchar(10),@StartDate,101) and convert(varchar(10),@EndDate,101)
'
exec sp_executesql @query
ERROR: Must declare the scalar variable "@StartDate".
I tried below and got error:Conversion failed when converting date and/or time from character string.
select *from ttisfc001491
where t_cmdt between convert(varchar(10),'+@StartDate+',101) and convert(varchar(10),'+@EndDate+',101)