alter TRIGGER [dbo].[khupdate_mycyy]
ON [dbo].[t_Organization]
FOR insert,update
AS
declare @fitemid int
select @fitemid=fitemid from inserted
if exists(select 1 from t_CustInfoMapp where FCustomer=@fitemid)
begin
update t_CustInfoMapp set
FInvCustName=v2.FName,FTaxpayerCode=isnull(v2.FTaxNum,''),FCompAddrPhone=isnull(v2.FAddress,''),FBankAndAccount=isnull(v2.FBank,'')+' '+isnull(FAccount,''),FContactNum=isnull(v2.FPhone,''),FEmail=isnull(v2.FEmail,'')
from t_CustInfoMapp v1
join t_Organization v2 on v1.FCustomer=v2.FItemID
where v2.fitemid=@fitemid
end
else
begin
declare @finterid int
declare @fbillno varchar(20)
exec GetICMaxNum 't_CustInfoMapp',@finterid output,1
exec p_BM_GetBillNo 1000201,@fbillno output
insert into t_CustInfoMapp
select @finterid,1000201,@fbillno,FName,ISNULL(FTaxNum,''),ISNULL(FAddress,''),ISNULL(fitemid,''),ISNULL(FBank,'')+' '+ISNULL(FAccount,''),0,ISNULL(FPhone,''),
ISNULL(FEmail,'') from inserted
end