gpt4 book ai didi

sql-server - 在具有IF条件的情况下在SQL Server中引发错误(THROW命令)-SQL Server

转载 作者:行者123 更新时间:2023-12-03 08:09:37 25 4
gpt4 key购买 nike

我正在尝试将脚本从RAISERROR命令更新为THROW命令。我处于IF语句条件中,如果条件为true,则抛出错误。对于RAISEERROR命令,我没有任何问题,但是当我更改为THROW命令时,则不可能。
RAISERROR命令:

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命令:
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

我收到此错误:

Msg 102, Level 15, State 1, Procedure uspAddProductToAuction, Line 14 [Batch Start Line 180]
Incorrect syntax near 'THROW'



先感谢您

最佳答案

Remarks
THROW语句之前的语句必须后面跟分号(;)语句终止符。

SET @IND_ADD_PRODUCT = 0;--<--!!
THROW 50001, 'The product is not in auction campaign discount or a product was not inserted',0;
END

关于sql-server - 在具有IF条件的情况下在SQL Server中引发错误(THROW命令)-SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61166549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com