select fseIdentity, fsePrincipalTerritoryId, fseCdrRecordId, fseInitialPrincipalTerritoryId, fsePrincipalDistributorId, distributor_code from tmpAcostaDannonDistributors where fseCdrRecordId is not null and fsePrincipalTerritoryId is not null update tbl_BRO_principalDistributors set mfrCustNbr = , principalTerritoryId = where ownerId = 14 and ownerType = 'BRO' and principalDistributorId = update tmpAcostaDannonDistributors set fseStatus = 'U' where fseIdentity = insert into tbl_BRO_principalDistributors ( ownerId, ownerType, principalTerritoryId, cdrRecordId, mfrCustNbr ) values ( 14, 'BRO', , , ) update tmpAcostaDannonDistributors set fseStatus = 'A', newPrincipalDistributorId = where fseIdentity = ---> select pt.mfrTerritoryNbr, pt.mfrTerritoryName, d.mfrCustNbr, cdr.cdr_dstName from tmpAcostaDannonDistributors i inner join tbl_BRO_PrincipalDistributors d on d.principalDistributorId = coalesce( i.newPrincipalDistributorId, i.fsePrincipalDistributorId ) inner join tbl_BRO_principalTerritories pt on pt.principalTerritoryId = d.principalTerritoryId inner join tbl_CDR_Distributors cdr on cdr.cdr_recordId= d.cdrRecordId and cdr.ownerId = d.ownerId and cdr.fsl_tablecode = d.ownerType where coalesce( i.newPrincipalDistributorId, i.fsePrincipalDistributorId ) is not null order by mfrTerritoryNbr, d.mfrCustNbr

#htmleditformat( mfrTerritoryNbr )# - #htmleditformat( mfrTerritoryName )#

#htmleditformat( mfrCustNbr )# - #htmleditformat( cdr_dstName )#