CREATE trigger dbo.TR_REVENUERECOGNITION_INSERTDELETEUPDATE_FAFRAISEDTOTAL
on dbo.REVENUERECOGNITION
after insert, update, delete
not for replication
as
begin
set nocount on;
declare c_constituentID cursor
read_only
for
--if not related to FAF event then the result in the cursor will be empty
select I.CONSTITUENTID, E.ID
from inserted I
inner join dbo.REVENUESPLIT RS with (nolock)
On I.REVENUESPLITID = RS.ID
inner join dbo.REVENUE R with (nolock)
ON RS.REVENUEID = R.ID
inner join dbo.EVENT E with (nolock)
on R.APPEALID = E.APPEALID
inner join dbo.EVENTEXTENSION ET with (nolock)
On E.ID = ET.EVENTID
union
select I.CONSTITUENTID, E.ID
from deleted I
inner join dbo.REVENUESPLIT RS with (nolock)
On I.REVENUESPLITID = RS.ID
inner join dbo.REVENUE R with (nolock)
ON RS.REVENUEID = R.ID
inner join dbo.EVENT E with (nolock)
on R.APPEALID = E.APPEALID
inner join dbo.EVENTEXTENSION ET with (nolock)
On E.ID = ET.EVENTID
declare @constituentID uniqueidentifier, @eventID uniqueidentifier
open c_constituentID
fetch next from c_constituentID into @constituentID, @eventId
while (@@fetch_status <> -1)
begin
if (@@fetch_status <> -2)
begin
exec dbo.USP_FAFRAISEDTOTAL_CALCULATE @EVENTID = @EVENTID, @CONSTITUENTID = @constituentID
end
fetch next from c_constituentID into @constituentID, @eventId
end
close c_constituentID
deallocate c_constituentID
end
|