select dstId, dstName, dstBranchId, 0 matchCount from tbl_DST_Distributors with (nolock) where dstParentCo = 4036 and len( dstBranchId ) = 3 order by dstBranchId with syscos as ( select dstId, dstName, dstBranchId from tbl_DST_Distributors with (nolock) where dstParentCo = 4036 and dstId = ) , acostaOperators as ( select s.dstId, dd.accountNumber, opr.companyName broCompanyName, opr.address broAddress, opr.city broCity, opr.state broState, opr.zipcode broZipCode from tbl_OPR_DistributionDetails dd with (nolock) inner join tbl_CDR_Distributors cdr with (nolock) on cdr.ownerId = dd.ownerId and cdr.fsl_tablecode = dd.ownerType and cdr.cdr_recordId = dd.cdr_recordId inner join syscos s on s.dstId = cdr.fsl_dstId inner join tbl_OPR_ClientOperators opr with (nolock) on opr.ownerId = dd.ownerId and opr.fsltablecode = dd.ownerType and opr.operatorId = dd.operatorId where dd.ownerId = 14 and dd.ownerType= 'BRO' and len( dd.accountNumber ) = 9 and left( dd.accountNumber, 3 ) = s.dstBranchId and nullif( opr.address, '' ) is not null and nullif( opr.city, '' ) is not null ) , syscoOperators as ( select opr.operatorId, s.dstId, ( s.dstBranchId + opr.mfrCustNum ) as fullAccountNumber -- opr.companyName, opr.address, opr.city, opr.state, opr.zipCode, cdr.cdr_dstName, s.dstBranchId, from tbl_OPR_CLientOperators opr with (nolock) inner join tbl_CDR_Distributors cdr with (nolock) on cdr.ownerId = opr.ownerId and cdr.fsl_tablecode = opr.fsltablecode and cdr.cdr_recordId = opr.distrib1 inner join syscos s on s.dstId = cdr.fsl_dstId where opr.ownerId = 4036 and opr.fsltablecode = 'DST' and len( opr.mfrCustNum ) = 6 and nullif( opr.address, '' ) is null and nullif( opr.city, '' ) is null ) select s.operatorId, broAddress, broCity, broState, broZipCode from syscoOperators s inner join acostaOperators a on a.dstId = s.dstId and a.accountNumber = s.fullAccountNumber update tbl_OPR_ClientOperators set address = , city = , state = , zipCode = , comments = '##addressAdded' where ownerId = 4036 and fsltablecode = 'DST' and operatorId =