USP_PDACCOUNTSEGMENTMAPPING_REFRESHVALUES

Refreshes unmapped values in PDACCOUNTSEGMENTMAPPING

Parameters

Parameter Parameter Type Mode Description
@PDACCOUNTSTRUCTUREID uniqueidentifier IN
@CHANGEAGENTID uniqueidentifier IN

Definition

Copy


create proc dbo.USP_PDACCOUNTSEGMENTMAPPING_REFRESHVALUES 
(@PDACCOUNTSTRUCTUREID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier = NULL)
as
set nocount on
declare @TableName varchar(255)
declare @sSQL varchar(1024)

select @TableName = t2.TABLENAME
from dbo.PDACCOUNTSTRUCTURE t1 inner join dbo.PDACCOUNTTABLESAVAILABLEFORSEGMENT t2 on t1.PDACCOUNTTABLESAVAILABLEFORSEGMENTID = t2.ID
where t1.ID = @PDACCOUNTSTRUCTUREID

exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;

delete from dbo.PDACCOUNTSEGMENTMAPPING
where PDACCOUNTSTRUCTUREID = @PDACCOUNTSTRUCTUREID
and PDACCOUNTSEGMENTVALUEID is null
and ISDEFAULT = 0

select @sSQL = 'insert into dbo.PDACCOUNTSEGMENTMAPPING (PDACCOUNTSTRUCTUREID, LONGDESCRIPTIONID, ISDEFAULT, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED) 
    select '''+convert(varchar(36),@PDACCOUNTSTRUCTUREID)+''',ID,0,'''+convert(varchar(36),@CHANGEAGENTID)+''','''+convert(varchar(36),@CHANGEAGENTID)+''',getdate(),getdate()
    from dbo.'+@TableName+' t1 where not exists(select * from dbo.PDACCOUNTSEGMENTMAPPING where PDACCOUNTSTRUCTUREID = '''+convert(varchar(36),@PDACCOUNTSTRUCTUREID)+''' and NULLIF(LONGDESCRIPTIONID,'''') = t1.ID)'

exec (@sSQL)