CREATE TRIGGER [goto_account_relhand] ON dbo.unify_goods
FOR INSERT,update
AS
declare @money money
declare @price money
declare @invoice_num varchar(16)
declare @sub_number varchar(16)
declare @point_reg varchar(6)
select @point_reg = inserted.point_reg from inserted
select @invoice_num = invoice_num,@sub_number = sub_number,@money = amount*price
from inserted where inserted.point_reg = @point_reg
if @point_reg = '0'
begin
select @invoice_num = invoice_num,@sub_number = sub_number,@money = amount*price
from inserted where inserted.point_reg = @point_reg
update dbo.unify_goods set money = convert(decimal(12,2),@money) from dbo.unify_goods aa,inserted where aa.invoice_num = @invoice_num
and aa.sub_number = @sub_number and aa.point_reg = @point_reg
end
else if @point_reg = '2'
begin
select @invoice_num = invoice_num,@sub_number = sub_number, @price = case amount when 0 then 0.00 else money/amount end
from inserted where inserted.point_reg = '2'
update dbo.unify_goods set price = convert(decimal(12,2),@price) from dbo.unify_goods aa,inserted
where aa.invoice_num = @invoice_num and aa.sub_number = @sub_number and aa.point_reg = '2'
end