UPDATE tbl_IMPORT_1FSDistributors SET dst_name = LTRIM(RTRIM(REPLACE(dst_name, CHAR(160), CHAR(32)))), dst_address = LTRIM(RTRIM(REPLACE(dst_address, CHAR(160), CHAR(32)))), dst_address2 = LTRIM(RTRIM(REPLACE(dst_address2, CHAR(160), CHAR(32)))) WHERE ownerId = AND ownerType = AND eai_batchId = select cdr.ownerId, cdr.fsl_tablecode, cdr.cdr_recordId, m.eai_importId, m.compareId, m.compareStatus from tbl_IMPORT_1FSDistributors m with (nolock) inner join tbl_CDR_Distributors cdr with (nolock) on cdr.cdr_recordId = m.cdr_recordId and cdr.ownerId = m.ownerId and cdr.fsl_tablecode = m.ownerType where m.eai_batchId= and m.ownerId = and m.ownerType = and nullif( cdr.fsl_dstId, 0 ) is null and m.compareId > 0 and m.compareStatus = 'G' and not ( m.ownerId = 66 and m.ownerType = 'MSC' ) update tbl_CDR_Distributors set fsl_dstId = , fsl_dstIdStatus = 'G', fsl_dstIdBy = , fsl_dstIdDate = where ownerId = and fsl_tablecode = and cdr_recordId = delete from tbl_IMPORT_1FSDistributors where eai_importId = delete imp from tbl_IMPORT_1FSDistributors imp where imp.eai_batchId = and imp.ownerId = and imp.ownerType = and imp.compareId > 0 and imp.compareStatus in ( 'Y' ) and not ( imp.ownerId = 66 and imp.ownerType = 'MSC' )