sp_executesqlexpects an input parameter in a unicode string. So you need to pass NVARCHAR(x)-string
SELECT 'hello' --creates the string "hello" as VARCHAR
SELECT N'hello' --create the string "hello" as unicode string (NVARCHAR)
in your line
exec sp_executesql @sql, N'@date datetime',@dt;
... N'@date datetime'is one input parameter.
Here you can learn more about sp_executesql
source
share