我试图int
在 raiserror 中显示我的变量@MaxAmount
和@MinAmount
Raiserror('Total Amount should be less than %s and Greater than %s',16,1,@MaxAmount,@MinAmount)
但我收到错误:
必须声明标量变量“@MaxAmount”。
我试图int
在 raiserror 中显示我的变量@MaxAmount
和@MinAmount
Raiserror('Total Amount should be less than %s and Greater than %s',16,1,@MaxAmount,@MinAmount)
但我收到错误:
必须声明标量变量“@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了解详细信息。
您需要将 %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)
我想你可以这样尝试:
DECLARE @MaxAmount int = 16;
DECLARE @MinAmount int = 1;
Raiserror('Total Amount should be less than %d and Greater than %d',@MaxAmount,@MinAmount)
如果您想了解有关 RAISERROR 的更多信息,请转到此处
上述解决方案对我不起作用,因为您还必须声明严重性和状态。没有它,结果将是这样的:
总金额应小于 (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)