i have written this query but its not working
declare @sTableName varchar(250)=null;
set @sTableName= 'tbl_WaterTurbidity';
declare @dt1 datetime=null ;
declare @dt2 datetime=null;
EXEC( 'select ISNULL(count(IsActive),0) as Act from '+ @sTableName +
' where IsActive=0 ' + ' AND (DateOfAnalysis between ' + @dt1 +
' AND '+ @dt2 +')' ) ;
purpose of query is passing table name as parameter to sp.
while running this query it shows an error of
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '1'.
if i change '9/1/2012' here from date 1 to 7,8,9 .. etc it shows respected error
means if i set '10/3/2012' then Incorrect syntax near '3'.
i have tried here several types of date maeans changing yyyy-mm-dd fashion to dd-MM-yyyy .. but there is same error .
what is the reason ?