Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get "Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'." when I try to use sp_executesql?

Why do I get this error

Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.

when I try to use sp_executesql?

like image 989
Manoj Wadhwani Avatar asked Apr 30 '10 10:04

Manoj Wadhwani


1 Answers

Sounds like you're calling sp_executesql with a VARCHAR statement, when it needs to be NVARCHAR.

e.g. This will give the error because @SQL needs to be NVARCHAR

DECLARE @SQL VARCHAR(100) SET @SQL = 'SELECT TOP 1 * FROM sys.tables' EXECUTE sp_executesql @SQL 

So:

DECLARE @SQL NVARCHAR(100) SET @SQL = 'SELECT TOP 1 * FROM sys.tables' EXECUTE sp_executesql @SQL 
like image 197
AdaTheDev Avatar answered Oct 21 '22 03:10

AdaTheDev