select top 1 batchId, batchTime from tbl_EAI_InboundBatches with (nolock) where ownerId = and ownerType = and fileFormat = '$NXT_CONTACT_EXPORT_CSV' and batchTime < and status = 'OK' order by batchTime desc drop table if exists [#_tempTable#]; with export as ( select ownerId, ownerType, partnerId as operator_id, partnerName as company_name, fspro_userId as contact_id, firstname as contact_first_name, lastname as contact_last_name, CASE WHEN partnerPrimaryContact = 1 THEN 'Y' ELSE 'N' END AS primary_contact, caJobFunctionText as contact_job_function, email as contact_email, title as contact_title, phone as contact_phone, cellphone as contact_mobile_phone, CASE WHEN emailYesNo = 1 THEN 'Y' ELSE 'N' END AS contact_allow_email, address1 as contact_address, address2 as contact_address_2, city as contact_city, state as contact_state, zipCode as contact_zipcode, preferredLanguageCode, preferredLanguageName as contact_preferred_language from tbl_DW_CRMContacts_#qmd_batch.ownerType##qmd_batch.ownerId# with (nolock) where partnertype = 'OPR' ) select operator_id,company_name, contact_id, contact_first_name, contact_last_name, primary_contact, contact_job_function, contact_email, contact_title, contact_phone, contact_mobile_phone, contact_allow_email, contact_preferred_language, contact_address,contact_address_2,contact_city,contact_state,contact_zipcode into [#_tempTable#] from export
Exported #lsnumberformat( _exportCount )# Contacts
update tbl_EAI_inboundBatches set fileName = , ttlDays = 365 where batchId = and ownerId = and ownerType =