Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

sql-server

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.

like image 205
JamesBB Avatar asked Aug 18 '16 17:08

JamesBB


1 Answers

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;
like image 168
Evaldas Buinauskas Avatar answered Sep 21 '22 18:09

Evaldas Buinauskas