select distinct ownerId, ownerType, cdr_recordId, fspro_userid, recordSource, company_id, company_name, company_type, company_phone, company_address1, company_address2, company_city, company_state, company_zip, company_last_modify_date from tbl_IMPORT_ClientDistributors i where i.recordSource = and i.ownerId = and i.ownerType = select listId from tbl_LST_partnerLists where ownerId = and ownerType = and listName = and listType = 'SYSTEM' and partnerType = 'CDR' SET NOCOUNT OFF INSERT INTO tbl_LST_PartnerLists ( ownerId, ownerType, listName, listType, createdBy, partnerType, locked ) VALUES ( , , , , , , 'Y' ) SELECT listId = @@identity SET NOCOUNT ON set nocount on insert into tbl_CDR_Distributors ( ownerId, fsl_tablecode, cdr_dstname, cdr_dstaddress1, cdr_dstaddress2, cdr_dstcity, cdr_dststate, cdr_dstzip, recordSource, createDate, lastUpdated, setMethod) values ( , , , , , , , , , { fn now() }, , 2 ) select cdr_recordId = @@identity set nocount off update tbl_IMPORT_ClientDistributors set cdr_recordId = where company_id = insert into tbl_LST_PartnerListItems (listId, partnerId ) values( , ) select importId, ownerId, ownerType, cdr_recordId, fspro_userid, recordSource, contact_last_name, contact_first_name, contact_fax, contact_phone, contact_mobile_phone, contact_email, contact_last_modify_date, primary_contact_indicator, contact_title, contact_type from tbl_IMPORT_ClientDistributors ci where ci.recordSource = and ci.ownerId = and ci.ownerType = and ci.cdr_recordId is not null and ci.fspro_userid is null select jobFunctionId from qmd_partnerContactJobFunctions where jobFunctionName = set nocount on insert into tbl_FSPro_members ( firstName, lastName, email, phone, fax, cellPhone, officeAddrSame, createDate, lastUpdated, originalSource, orgId, orgType, ownerId, fsl_tablecode, title, cajobfunction ) values( , , , , , , 1, { fn now() }, , , , , , , , ) select fspro_userid = @@identity set nocount off update tbl_CDR_Distributors set primaryContactId = where cdr_recordId = update tbl_IMPORT_ClientDistributors set fspro_userId = where importId = select firstName, lastName, fspro_userid, orgId, orgType, email, originalSource from tbl_Fspro_members where originalSource = select cdr.primaryContactId, cdr.cdr_recordId, cdr_dstName, cdr_dstaddress1, cdr_dstaddress2, cdr_dstcity, cdr_dststate, cdr_dstzip, cdr.primaryContactId, cdr.createDate, case when cdr.primaryContactId = m.fspro_userid then 'Y' else 'N' end primaryContact, m.fspro_userid, m.orgId, m.orgType, m.firstName, m.lastName, m.phone, m.fax, m.cellPhone ,m.email, ter.name territoryName, cdr.setMethod, m.cajobfunction, i.contact_type from tbl_CDR_Distributors cdr inner join tbl_IMPORT_ClientDistributors i on i.cdr_recordId = cdr.cdr_recordId inner join tbl_FSPro_Members m on m.fspro_userId = i.fspro_userid left outer join tbl_TER_Territories ter on ter.territoryId = cdr.cdr_territoryId order by territoryName, cdr_dstName, cdr.cdr_recordId
*** Preview *** #_recordSource# - #lsDateFormat( now() )# at #lstimeformat( Now() )# *** Preview ***
Distributor Address Contact Territory
#cdr_dstName#
#lsdateformat( createDate, "mm/dd/yyyy" )#
#cdr_dstaddress1#
#cdr_dstaddress2#
#cdr_dstcity#, #cdr_dststate# #cdr_dstzip#

#firstName# #lastName# #caJobFunction# - #contact_type#
&##160;&##160;email:#email#
&##160;&##160;phone:#phone#
&##160;&##160;cell:#cellPhone#
&##160;&##160;fax:#fax#
#setMethod#: #territoryName#Unassigned
#application.datasource#: #qmd_check.recordCount#(#importCount#) Records Imported
#resultsHTML# #resultsHTML#