select top 1 batchId, batchTime from tbl_EAI_InboundBatches with (nolock) where ownerId = and ownerType = and fileFormat = '$KELLANOVA_SALES_CALL_EXPORT' and batchTime < and status = 'OK' order by batchTime desc delete from tbl_EXPORT_Kellanova_Sales_call where ownerId = and ownertype = and eai_batchId = insert into tbl_EXPORT_Kellanova_Sales_call( ownerType, ownerId, eai_batchId, eai_lineNumber, salesperson , hs_timestamp , hs_activity_type , sku , sku_description , quantity , frequency , cases , estimated_order_date , call_update_date , hs_call_disposition , company_name , novalyticscallid , novalytics_id , customer_type , hs_call_body ) select ownerType, ownerId, #qmd_batch.batchId# as eai_batchId, row_number() over ( order by interactionId, sku ) as eai_lineNumber, salesRepFirstName + ' ' + salesRepLastName as salesperson , interactionDate as hs_timestamp , case when detailDisposition = 'FU' then 'Follow Up' when detailDisposition = 'STD' then 'Sale' when detailDisposition = 'NS' then 'No Sale' else detailDisposition end hs_activity_type , sku , skuDesc as sku_description , qty as quantity , qtyDuration as frequency , cases , estOrderDate as est_order_date , dispositionDate as call_update_date , case when disposition != '?' then 'COMPLETE' else 'OPEN' end hs_call_disposition , partnerName as company_name , interactionId as novalytics_call_id , partnerId as novalytics_id , CASE WHEN partnerType = 'OPR' THEN 'Operator' WHEN partnerType = 'CDR' THEN 'Distributor' END AS customer_type , detailComment as hs_call_body from tbl_DW_Interactions_MFR207 with (nolock) where year( dispositionDate ) >= 2024 and skuId > 0 and disposition != '?' and dispositionDate >= order by interactionId, sku update tbl_EAI_InboundBatches set loadedColumns = 'salesperson,hs_timestamp,hs_activity_type,sku,sku_description,quantity,frequency,cases,estimated_order_date,call_update_date,hs_call_disposition,company_name,novalyticscallid,novalytics_id,customer_type,hs_call_body' where ownerId = and ownertype = and batchId =
Exported #lsnumberformat( _exportCount )# Records updated on or after #lsdateFormat( _cutoffDate, "MM/dd/yyyy" )#.
#encodeforHTML( _r.sql )#
select * from tbl_EXPORT_Kellanova_Sales_call with (nolock) where ownerId = and ownertype = and eai_batchId = order by eai_lineNumber