14

int変数を raiserrorに表示しようとしていますが@MaxAmount@MinAmount

Raiserror('Total Amount should be less than %s and Greater than %s',16,1,@MaxAmount,@MinAmount)

しかし、私はエラーが発生しています:

スカラー変数「@MaxAmount」を宣言する必要があります。

4

4 に答える 4

16

%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を確認してください。

于 2015-09-16T10:11:20.827 に答える
8

整数には %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)
于 2015-09-16T10:10:29.710 に答える
1

私はあなたがこの方法で試していると思います:

DECLARE @MaxAmount int = 16;
DECLARE @MinAmount int = 1;

Raiserror('Total Amount should be less than %d and Greater than %d',@MaxAmount,@MinAmount)

RAISERROR の詳細については、こちらをご覧ください。

于 2015-09-16T10:10:29.063 に答える