Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'
Here is one of the possible solution:
Convert your @sqlstr
to varchar(max)
and instead of EXECUTE sp_executesql
, use EXECUTE(@strsql)
.In this fashion you got your complete print query and it will also execute your query.Hope that it helps.
Declare variable as a nvarchar type when you are using command exec sp_executesql.Above you used varchar for @sqlstr variable.
Eg.
Declare @Sqlstr nvarchar(max)
SET @Sqlstr='...Your dynamic query...'
exec sp_executesql @Sqlstr
Note:Dont use brackets in exec command
sp_executesql takes NVARCHAR as parameter not VARCHAR, change varchar(max)
to nvarchar(max)
will fix the problem.
DECLARE @sqlstr AS nvarchar (max)