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

I get this error Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'. 

Example Query:
alter procedure Test
(@ReturnValue varchar(100)='')
as
begin
SET @ReturnValue = 'select ''hai'' ColumeName' 
execute SP_EXECUTESQL @ReturnValue
END
Solution:
This will give the error because @ReturnValue needs to be NVARCHAR.
SO change the VARCHAR variable to NVARCHAR .

Example:
alter procedure Test
(@ReturnValue Nvarchar(100)='')
as
begin
SET @ReturnValue = 'select ''hai'' ColumeName' 
execute SP_EXECUTESQL @ReturnValue
END
Execute the result:
declare @ret int
exec sp_executesql N'exec @ret = Test', N'@ret int OUTPUT', @ret = @ret OUTPUT
Problem Solved.

Post a Comment

0 Comments