user3005015 user3005015 - 3 months ago 11
SQL Question

Procedure expects parameter '@params' of type 'ntext/nchar/nvarchar'

this is my stored procedure:

ALTER PROCEDURE [dbo].[sp_Update_Projecttijden]
@tabelnaam NVARCHAR(30) ,
@starttijd DATETIME,
@eindtijd DATETIME,
@tijd FLOAT,
@startid INT,
@eindid INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
-- DECLARE @DATEVARCHAR NVARCHAR(4000);
DECLARE @SQLCommand NVARCHAR(MAX) = N'
UPDATE ' + QUOTENAME(@tabelnaam) + N'
SET Start = @starttijd
, Einde = @eindtijd
, Tijd = @tijd
, StartID = @startid
, EindID = @eindid

WHERE StartID = @startid AND EindID=@eindid';

EXECUTE dbo.sp_executesql @sqlCommand,
' N @starttijd DATETIME, @eindtijd DATETIME, @tijd FLOAT, @startid INT, @eindid INT'


, @starttijd
, @eindtijd
, @tijd
, @startid
, @eindid;

END


The error thrown is this:


Msg 214, Level 16, State 3, Procedure sp_executesql, Line 3 Procedure
expects parameter '@params' of type 'ntext/nchar/nvarchar'.


I have been looking at similar questions/answers, but could not really solve my problem.
All help is very much appreciated.

Answer

Issue is typo in your code. Notice that your N is in your string, not before it.
N before string identifies that following text is going to be in unicode, your error actually tells that your procedure expects unicode parameter and gets VARCHAR instead.

EXECUTE sys.sp_executesql @sqlCommand
    , N'@starttijd DATETIME, @eindtijd DATETIME, @tijd FLOAT, @startid INT, @eindid INT'
    , @starttijd
    , @eindtijd
    , @tijd
    , @startid
    , @eindid;
Comments