我们有时侯在录入凭证时,碰到进行数量金额核算的科目,但是如果不录入数量单价也可以保存.我公司就在实际中碰到,很多科目明细账核算时,忘记录入数量,结果查账时光有金额.所以做了一个触发器,进行控制,还请前辈进行指证.如果确实不需要输入数量单价,请删除触发器.本人水平有限,还请大家帮忙多测试,也多提意见,谢谢.
--查找临时表,删除。
if exists (select name from sysobjects where name = 'T_voucherentry_hzxw_insert'
and type='tr' )
drop trigger T_voucherentry_hzxw_insert
if exists (select name from sysobjects where name = 'Temp1'
and type='U' )
drop table temp1
set quoted_identifier on
go
set ansi_nulls on
go
--建立触发器
create trigger T_voucherentry_hzxw_insert on T_voucherentry
for insert,update
as
declare @Faccountid integer
declare @fquantities bit
declare @fquantity DECIMAL (28, 10)
declare @funitprice DECIMAL (28, 10)
set nocount on
--从插入记录中取值
select @faccountid=faccountid,
@fquantity=fquantity,
@funitprice=funitprice
from inserted
--判断有数量金额核算的会计科目的数量和单价是否为0
if (@fquantity=0 or @funitprice=0)
and @faccountid=(select faccountid from T_account where fquantities=1 and faccountid=@Faccountid)
/*select T_account.faccountid,
fquantity,
funitprice
from T_account join inserted
on (t_account.faccountid=inserted.faccountid)
where T_account.fquantities=1 */
begin
ROLLBACK TRAN
raiserror('提醒您数量金额科目未填入数量或单价',18,18)
end
go
set quoted_identifier off
go
set ansi_nulls on
go
实际工作中,有可能碰到只输入金额而不用数量的,比如说是材料运费,所以该控制的应用范围有限,希望对大家能有帮助.
补充时间:2008-9-24 16:17:45