sql-server - Raising Errors in SQL Server ( THROW Command) with IF condition - SQL Server
问题描述
I am trying to update my script from the RAISERROR
command to the THROW
command. I am in an IF
statement condition and if the condition is true, the throw the error. For the RAISEERROR
command I do not have an issue, however when I change to the THROW
command, there is no possible.
RAISERROR
command:
CREATE OR ALTER PROCEDURE Auction.uspAddProductToAuction
(@ProductID INT,
@ExpireDate DATETIME = NULL,
@InitialBidPrice MONEY = NULL)
AS
DECLARE @IND_ADD_PRODUCT TINYINT
SET @IND_ADD_PRODUCT = 1
IF ([Auction].[ufnGetStock](@ProductID) = 0) --> true
BEGIN
SET @IND_ADD_PRODUCT = 0
RAISERROR ('The product is not in auction campaign discount or a product was not inserted', 1, 0)
END
THROW command:
CREATE OR ALTER PROCEDURE Auction.uspAddProductToAuction
(@ProductID INT,
@ExpireDate DATETIME = NULL,
@InitialBidPrice MONEY = NULL)
AS
DECLARE @IND_ADD_PRODUCT TINYINT
SET @IND_ADD_PRODUCT = 1
IF ([Auction].[ufnGetStock](@ProductID) = 0) --> true
BEGIN
SET @IND_ADD_PRODUCT = 0
THROW 50001, 'The product is not in auction campaign discount or a product was not inserted', 0
END
I get this error:
Msg 102, Level 15, State 1, Procedure uspAddProductToAuction, Line 14 [Batch Start Line 180]
Incorrect syntax near 'THROW'
Thank you in advance
解决方案
备注 THROW 语句之前的语句必须后跟分号 (;) 语句终止符。
SET @IND_ADD_PRODUCT = 0;--<--!!
THROW 50001, 'The product is not in auction campaign discount or a product was not inserted',0;
END
推荐阅读
- go - 使用反射检索类型别名备用名称
- ms-access - Access Vba - 如何将记录集的当前记录设置为另一个记录集
- ethereum - 现在完整的 geth 以太坊节点的大小是多少?
- angular - Angular 2 Typescript 从文件系统转换问题中检索 jpeg 图像
- r - ggplot2:使用 geom_point 增加分类轴刻度之间的空间
- java - java程序找不到符号类Node但我导入了它
- r - readr:传递一串列类
- vue.js - vue-devtools 总是被 nuxt.js 禁用
- c - 预处理器运算符“定义”的优先级?
- python - 如何从字典中编写一个文本文件,其中每个键都是一个新行?