ERROR MESAGGE:
“Procedure expects parameter ‘@statement’ of type ‘ntext/nchar/nvarchar’.”
EXPLANATION:
You may see this error message when you run the command in a variable with the sp_executesql system SP.
Example:
1 2 3 |
DECLARE @command VARCHAR(150) SET @command = 'SELECT * FROM MYTABLE' EXEC sp_executesql @command |
Or if you run a command directly without using any variables, you will see the same error message:
1 |
EXEC sp_executesql 'SELECT * FROM MYTABLE' |
SOLUTION:
In fact, the error is clearly written in the error message. The @statement parameter that you will use for the sp_executesql system SP should be UNICODE.
The correct versions of the above examples are as follows:
1 2 3 |
DECLARE @command NVARCHAR(150) SET @command= N'SELECT * FROM MYTABLE' EXEC sp_executesql @command |
and
1 |
EXEC sp_executesql N'SELECT * FROM MYTABLE' |