SQL2008触发器RAISERROR
请教在这个触发器里使用RAISERROR向客户端抛出一个错误信息告知用户,同时也要删除一笔单据,为什么DELETE语句(DELETE dbo.SHCBF WHERE BF001=@BF001)就不执行了,如果没有'RAISERROR',则可以执行,是不是RAISERROR和DELETE不能同时存在
以下是代码,谢谢,赐教!!
ALTER TRIGGER Tri_CheckBG013
ON SHCBG
INSTEAD OF INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @BG013 DECIMAL(16,6),@SUMBG013 DECIMAL(16,6),@BF005 CHAR(10),@BG007 CHAR(4),@BG008 CHAR(11),@TA015 DECIMAL(16,6),@STRMESSAGE VARCHAR(200),@BG017 CHAR(1),@BF001 CHAR(20)
SELECT @BF001=LTRIM(RTRIM(BG001)),@BF005=BF005,@BG007=BG007,@BG008=BG008,@BG013=BG013,@BG017=BG017 FROM INSERTED A
INNER JOIN dbo.SHCBF B
ON A.BG001=B.BF001
IF @BG017 = '1'
BEGIN
SELECT @SUMBG013=SUM(BG013) FROM dbo.SHCBF A
INNER JOIN dbo.SHCBG B
ON A.BF001=B.BG001
WHERE A.BF005=@BF005 AND BG007=@BG007 AND BG008=@BG008
SELECT @TA015=TA015 FROM ad2011.dbo.MOCTA
WHERE TA001=@BG007 AND TA002=@BG008
SET @STRMESSAGE ='工艺:'+@BF005+',累计报工量:'+CAST((ISNULL(@BG013,0)+ISNULL(@SUMBG013,0)) AS VARCHAR)+ '不可大于工单:'+@BG007+'-'+@BG008+'预计产量:'+CAST(@TA015 AS VARCHAR)+','+@BF001;
IF ISNULL(@BG013,0)+ISNULL(@SUMBG013,0) > @TA015+@TA015*0.1
BEGIN
BEGIN
BEGIN TRAN
DELETE dbo.SHCBF WHERE BF001=@BF001;
COMMIT TRAN
END
BEGIN
BEGIN TRAN
RAISERROR(@STRMESSAGE,16,1) WITH NOWAIT;
COMMIT TRAN
END
END
ELSE
BEGIN
INSERT INTO dbo.SHCBG
SELECT * FROM INSERTED
END
END
ELSE
BEGIN
INSERT INTO dbo.SHCBG
SELECT * FROM INSERTED
END
-- Insert statements for trigger here
END