Tom Stevens
Tom Stevens

Reputation: 335

RAISERROR raises substitution parameter error

following T-Sql code:

DECLARE @usu VARCHAR(10);
SET @usu = 'TOM';
PRINT @usu;
RAISERROR ('Name of USU is %i ',14,2,@usu);

returns following error:

Msg 2786, Level 16, State 1, Line 4
The data type of substitution parameter 1 does not match the expected type of the format specification.

Does anyone know how I can get rid of this error?

Upvotes: 4

Views: 16141

Answers (3)

gregjer
gregjer

Reputation: 2843

Try to change that:

RAISERROR ('Name of USU is %i ',14,2,@usu); 

into that

RAISERROR ('Name of USU is %s ',14,2,@usu); 

since @usu is varchar(10) and %i means signed integer

Upvotes: 7

sunysen
sunysen

Reputation: 2351

try

DECLARE @usu VARCHAR(10);
SET @usu = 'TOM'; 
PRINT @usu; 
--modify this line  RAISERROR ('Name of USU is %i',14,2,@usu);
RAISERROR ('Name of USU is %s',14,2,@usu);

http://msdn.microsoft.com/en-us/library/ms178592.aspx

Upvotes: 2

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

Yeah, change your format to Name of USU is %s, the %i means the value of @usu is a signed integer. All of the format types are clearly documented on MSDN.

Upvotes: 8

Related Questions