抛出错误 - 错误消息中正确的 % 格式值
Throwing errors - The correct % formatting values in error message
我试图从 SQL 服务器中的存储过程中抛出自定义错误,但在编译时出现错误。问题很清楚。我正在尝试显示位类型参数的值,但我认为我的格式语句是错误的。我有以下内容:
EXEC sys.sp_addmessage
@msgnum = 60000
,@severity = 16
,@msgText = N'Bad parameter. You cannot pass NULLs to this procedure, UseAlternateEquity (%i), AlternateEquity (%d), PushEmail (%i)'
,@lang = NULL;
declare @msg1 NVARCHAR(2048) = FORMATMESSAGE(60000, @UseAlternateEquity, @AlternateEquity, @PushEmail);
throw 60000, @msg1, 1;
变量@UseAlternateEquity
和@PushEmail
的类型是bit
有人能告诉我合适的格式类型是什么吗?我找遍了高低都找不到答案
只需将您的@UseAlternateEquity 和@PushEmail 转换为另一种类型,然后再传递它们。您可以像这样将它们转换为 varchar 或 int
(我在 2008 年所以我可以 RAISERROR)
declare @UseAlternateEquityand bit = 1,
@PushEmailare bit = 0,
@AlternateEquity bit = 1;
declare @UseAlternateEquityand_1 int = @UseAlternateEquityand,
@PushEmailare_1 int = @PushEmailare,
@AlternateEquity_1 int = @AlternateEquity;
RAISERROR ( N'Bad parameter. You cannot pass NULLs to this procedure, UseAlternateEquity (%u), AlternateEquity (%u), PushEmail (%u)',
16,
1,
@UseAlternateEquityand_1,
@AlternateEquity_1,
@PushEmailare_1);
我试图从 SQL 服务器中的存储过程中抛出自定义错误,但在编译时出现错误。问题很清楚。我正在尝试显示位类型参数的值,但我认为我的格式语句是错误的。我有以下内容:
EXEC sys.sp_addmessage
@msgnum = 60000
,@severity = 16
,@msgText = N'Bad parameter. You cannot pass NULLs to this procedure, UseAlternateEquity (%i), AlternateEquity (%d), PushEmail (%i)'
,@lang = NULL;
declare @msg1 NVARCHAR(2048) = FORMATMESSAGE(60000, @UseAlternateEquity, @AlternateEquity, @PushEmail);
throw 60000, @msg1, 1;
变量@UseAlternateEquity
和@PushEmail
的类型是bit
有人能告诉我合适的格式类型是什么吗?我找遍了高低都找不到答案
只需将您的@UseAlternateEquity 和@PushEmail 转换为另一种类型,然后再传递它们。您可以像这样将它们转换为 varchar 或 int (我在 2008 年所以我可以 RAISERROR)
declare @UseAlternateEquityand bit = 1,
@PushEmailare bit = 0,
@AlternateEquity bit = 1;
declare @UseAlternateEquityand_1 int = @UseAlternateEquityand,
@PushEmailare_1 int = @PushEmailare,
@AlternateEquity_1 int = @AlternateEquity;
RAISERROR ( N'Bad parameter. You cannot pass NULLs to this procedure, UseAlternateEquity (%u), AlternateEquity (%u), PushEmail (%u)',
16,
1,
@UseAlternateEquityand_1,
@AlternateEquity_1,
@PushEmailare_1);