我試圖表現出RAISERROR @MaxAmount
我int
變量和@MinAmount
如何使用變量在SQL RAISERROR
Raiserror('Total Amount should be less than %s and Greater than %s',16,1,@MaxAmount,@MinAmount)
但是我得到錯誤:
Must declare the scalar variable "@MaxAmount".
我試圖表現出RAISERROR @MaxAmount
我int
變量和@MinAmount
如何使用變量在SQL RAISERROR
Raiserror('Total Amount should be less than %s and Greater than %s',16,1,@MaxAmount,@MinAmount)
但是我得到錯誤:
Must declare the scalar variable "@MaxAmount".
%s
用於varchar
和您的變量的類型int
因此你需要嘗試使用正確的格式說明即,%d
DECLARE @MaxAmount int = 16;
DECLARE @minAmount int = 1;
Raiserror('Total Amount should be less than %d and Greater than %d',@MaxAmount,@MinAmount)
檢查RAISEERROR瞭解詳情。
我覺得你這樣試試:
DECLARE @MaxAmount int = 16;
DECLARE @MinAmount int = 1;
Raiserror('Total Amount should be less than %d and Greater than %d',@MaxAmount,@MinAmount)
如果您想了解更多信息關於RAISERROR,go here
您需要使用%I作爲整數,如前所述,在使用前聲明變量。
declare @MaxAmount int, @MinAmount int
select @MaxAmount = 50, @MinAmount = 5
Raiserror('Total Amount should be less than %i and Greater than %i',16,1,@MaxAmount,@MinAmount)
其基本的,你必須在查詢中使用它之前聲明變量。 –
我確實聲明瞭,但是當我在raiserror中使用它時出現了輸入錯誤。解決了! – Nuke