![]() |
---|
CREATE trigger [dbo].[TR_CAMPAIGNPRIORITY_IU_ORGANIZATIONAMOUNT] on [dbo].[CAMPAIGNPRIORITY] 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(GOAL) begin declare @ORGANIZATIONCURRENCYID uniqueidentifier = dbo.UFN_CURRENCY_GETORGANIZATIONCURRENCY(); update dbo.CAMPAIGNPRIORITY set CAMPAIGNPRIORITY.ORGANIZATIONAMOUNT = CAMPAIGNPRIORITY.GOAL, CAMPAIGNPRIORITY.CHANGEDBYID = CAMPAIGNPRIORITY.CHANGEDBYID, CAMPAIGNPRIORITY.DATECHANGED = CAMPAIGNPRIORITY.DATECHANGED from inserted inner join dbo.CAMPAIGNPRIORITY on inserted.ID = CAMPAIGNPRIORITY.ID inner join dbo.CAMPAIGN on CAMPAIGNPRIORITY.CAMPAIGNID = CAMPAIGN.ID where CAMPAIGNPRIORITY.CURRENCYEXCHANGERATEID is null and (CAMPAIGN.BASECURRENCYID is null or CAMPAIGN.BASECURRENCYID = @ORGANIZATIONCURRENCYID) and ( CAMPAIGNPRIORITY.ORGANIZATIONAMOUNT <> CAMPAIGNPRIORITY.GOAL or CAMPAIGNPRIORITY.GOAL = 0 ); end end |