create trigger Fittings_Insert_Tr ON Fittings
instead of insert
as
declare
@f_name varchar(50),
@f_no1 varchar(50),
@f_no2 varchar(50),
@b_id int,
@t_id int,
@p_id int,
@f_size varchar(50),
@f_remark varchar(500),
@f_photograpt varchar(500),
@f_amount int
begin
select @f_name=f_name,@f_no1=f_no1,@f_no2=f_no2,@b_id=b_id,@t_id=t_id,@p_id=p_id,@f_size=f_size,@f_remark=f_remark,@f_photograpt=f_photograpt,@f_amount=f_amount from inserted
if not exists(select * from Fittings where f_name=@f_name and f_no1=@f_no1 and f_no2=@f_no2 and b_id=@b_id and t_id=@t_id and p_id=@p_id)
begin
insert Fittings (
f_name,f_no1,f_no2,b_id,t_id,p_id,f_sort,f_commend,f_uploadTime,f_updatetime,f_availabilitytime,f_amount,f_size,f_state,f_minprice,f_price,f_remark,f_locus,f_photograpt
) select
f_name,f_no1,f_no2,b_id,t_id,p_id,'CT','否',getdate(),getdate(),365,f_amount,f_size,'未测试',0,0,f_remark,f_locus,f_photograpt
from inserted
end
else
begin
update Fittings set f_size=@f_size , f_remark=@f_remark ,f_photograpt=@f_photograpt , f_amount=f_amount+@f_amount where f_name=@f_name and f_no1=@f_no1 and f_no2=@f_no2 and b_id=@b_id and t_id=@t_id and p_id=@p_id
end
end
go