张志峰的博客

水滴石川,积少成多。

导航

要用的触发器

Posted on 2015-12-25 17:58  ╰★张志峰★╮  阅读(179)  评论(0编辑  收藏  举报

IF OBJECT_ID ('ppSDetail_PPIn','TR') IS NOT NULL
DROP TRIGGER ppSDetail_PPIn;
GO

CREATE TRIGGER ppSDetail_PPIn ON ppSDetail
AFTER INSERT
AS
DECLARE @iBillType INTEGER
DECLARE @cBillCode VARCHAR(100)


SELECT @iBillType=iBillType,@cBillCode=cBillCode FROM Inserted

IF @iBillType = 0
BEGIN
IF EXISTS(SELECT 1 FROM
ppSDetail a
LEFT JOIN
PPInDetailPlace b
ON b.cbillcode=a.cBillCode
AND a.cPaperCode=b.cpapercode
WHERE a.cBillCode=@cBillCode AND b.cpapercode IS NULL)
BEGIN
RAISERROR ('触发器:确认入库时出现入库单(" + @cBillCode + ")不存在的纸写入了实物账中的问题,请找系统管理员报告这个错误!', 16, 1);
ROLLBACK TRANSACTION;
RETURN
END
END