I am using a dynamic query wherein I want to use the variable which holds the datetime, whenever I execute the query it says cannot convert datetime from string, when I cast tha
Run this example and adapt it to your code. (There are not 3 contiguous single quotes)
Declare @FromDATE datetime
;Declare @ToDATE datetime
;set @FromDATE = getdate()
;set @ToDATE = @FromDATE
;Print 'WHERE TillDate BETWEEN ' + char(39) + CONVERT(VARCHAR(10),@FromDATE, 101)
+ char(39) + ' and ' + char(39) + CONVERT(VARCHAR(10),@ToDATE, 101) + char(39)