![]() |
---|
CREATE trigger [dbo].[TR_CAMPAIGNGOAL_IU_ORGANIZATIONAMOUNT] on [dbo].[CAMPAIGNGOAL] after insert, update not for replication as begin set nocount on; -- if we try to save an amount without explicitly setting an organization amount and an exchange rate, -- copy the amount to the organization amount. if update(AMOUNT) begin declare @ORGANIZATIONCURRENCYID uniqueidentifier = dbo.UFN_CURRENCY_GETORGANIZATIONCURRENCY(); update dbo.CAMPAIGNGOAL set CAMPAIGNGOAL.ORGANIZATIONAMOUNT = CAMPAIGNGOAL.AMOUNT, CAMPAIGNGOAL.CHANGEDBYID = CAMPAIGNGOAL.CHANGEDBYID, CAMPAIGNGOAL.DATECHANGED = CAMPAIGNGOAL.DATECHANGED from inserted inner join dbo.CAMPAIGNGOAL on inserted.ID = CAMPAIGNGOAL.ID inner join dbo.CAMPAIGN on CAMPAIGNGOAL.CAMPAIGNID = CAMPAIGN.ID where CAMPAIGNGOAL.CURRENCYEXCHANGERATEID is null and (CAMPAIGN.BASECURRENCYID is null or CAMPAIGN.BASECURRENCYID = @ORGANIZATIONCURRENCYID) and ( CAMPAIGNGOAL.ORGANIZATIONAMOUNT <> CAMPAIGNGOAL.AMOUNT or CAMPAIGNGOAL.AMOUNT = 0 ); end end |