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 回答
0

上述解决方案对我不起作用,因为您还必须声明严重性和状态。没有它,结果将是这样的:

总金额应小于 (null) 且大于 (null)

你可以试试这个:

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

Raiserror('Total Amount should be less than %d and Greater than %d', 16, 1, @MaxAmount, @MinAmount)
于 2020-06-01T07:14:38.827 回答