我试图表现出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