tags:

views:

312

answers:

2

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

when i m trying to execute sp then it through this error.

Could you please help it out.

+2  A: 

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
AdaTheDev
A: 

The solution is to put an N in front of both he type and the SQL string to indicate it is a double-byte character string:

DECLARE @SQL NVARCHAR(100) 
SET @SQL = N'SELECT TOP 1 * FROM sys.tables' 
EXECUTE sp_executesql @SQL
Daniel Renshaw
That isn't the solution here - that would still error as you have it. The solution is to change the VARCHAR variable to NVARCHAR
AdaTheDev
AdaTheDev, you're right, I've fixed that now
Daniel Renshaw