UFN_CHECKDETAIL_AUCTIONPURCHASESCHANGED
Determines if the auction purchases have changed for a revenue record.
Return
| Return Type | 
|---|
| bit | 
Parameters
| Parameter | Parameter Type | Mode | Description | 
|---|---|---|---|
| @REVENUEID | uniqueidentifier | IN | |
| @REVENUESTREAMS | xml | IN | 
Definition
 Copy 
                                    
            create function dbo.UFN_CHECKDETAIL_AUCTIONPURCHASESCHANGED
            (
                @REVENUEID uniqueidentifier,
                @REVENUESTREAMS xml
            )
            returns bit
            with execute as caller
            as begin
                declare @OLDPURCHASES table 
                (
                    ID uniqueidentifier, 
                    APPLICATIONID uniqueidentifier, 
                    APPLIED money,
                    APPLICATIONCODE tinyint
                );
                declare @UPDATEDPURCHASES table 
                (
                    ID uniqueidentifier, 
                    APPLICATIONID uniqueidentifier, 
                    APPLIED money,
                    APPLICATIONCODE tinyint
                );
                declare @STREAMCOUNT int
                declare @CHANGED as bit
                set @CHANGED = 0;
                insert into @OLDPURCHASES
                    select ID, APPLICATIONID, APPLIED, APPLICATIONCODE
                    from dbo.UFN_REVENUE_GETAPPLICATIONS(@REVENUEID)
                    where APPLICATIONCODE = 12;
                insert into @UPDATEDPURCHASES
                    select ID, APPLICATIONID, APPLIED, APPLICATIONCODE
                    from dbo.UFN_REVENUE_GETAPPLICATIONS_FROMXML(@REVENUESTREAMS)
                    where APPLICATIONCODE = 12;
                select @STREAMCOUNT = count(ID) from @OLDPURCHASES;
                if @STREAMCOUNT <> (select count(*) from @UPDATEDPURCHASES) 
                    set @CHANGED = 1;
                if @CHANGED = 0
                begin
                    select @STREAMCOUNT = count([NEW].ID)
                    from @UPDATEDPURCHASES as [NEW] 
                    inner join @OLDPURCHASES as [OLD] on [OLD].ID = [NEW].ID 
                    where ([NEW].APPLICATIONID = [OLD].APPLICATIONID
                            or [NEW].APPLICATIONID is null and [OLD].APPLICATIONID is null)
                        and [NEW].APPLIED = [OLD].APPLIED
                        and [NEW].APPLICATIONCODE = [OLD].APPLICATIONCODE
                    if @STREAMCOUNT <> (select count(ID) from @UPDATEDPURCHASES)
                        set @CHANGED = 1;
                end
                return @CHANGED;
            end