DECLARE @docstatus int
SELECT @docstatus=docstatus
FROM fardoc WITH (NOLOCK)
WHERE DocCode=@doccode
IF @docstatus=100 -------这里100代表单据已确认状态
BEGIN
insert into 表1(字段省略)
select 字段省略
from 表2 with (nolock)
where doccode=@doccode
END
ELSE
BEGIN
RAISERROR('插入子帐失败!',16,1)
RETURN
END
DECLARE @docstatus int
SELECT @docstatus=docstatus
FROM fardoc WITH (NOLOCK)
WHERE DocCode=@doccode
IF @docstatus=100 -------这里100代表单据已确认状态
BEGIN
insert into 表1(字段省略)
select 字段省略
from 表2 with (nolock)
where doccode=@doccode
END
ELSE
BEGIN
RAISERROR('插入子帐失败!',16,1)
rollback --这里回滚
RETURN
END