2013-10-10 28 views
1

下面的T-SQL代碼:
RAISERROR引發替代參數錯誤

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

返回以下錯誤:

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.

有誰知道我怎樣才能擺脫這種錯誤的?

+2

我會停止做錯誤信息暗示的。 – Kermit

+0

選擇嚴重性14的任何特定原因?通常用於[權限不足](http://www.sommarskog.se/error-handling-I.html#severitylevels) –

+0

請更新相當諷刺的標題,當然RAISEERROR會引發錯誤;) – codemonkeh

回答

4

是的,將您的格式更改爲Name of USU is %s,%i表示值爲@usu是一個有符號的整數。所有的格式類型都清晰可見documented on MSDN

3

試圖改變的是:

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

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

因爲@usu爲varchar(10)和%I手段SIGNE d整數

相關問題