select top 1 batchId
from tbl_EAI_inboundBatches
where ownerId = 26 and ownerType = 'MFR' and fileFormat = 'JMS_610_Invoice_Detail' and status = 'OK'
and parentBatchId is null
order by batchId desc
select mappingType, fiestaCode, sourceCode
from FiestaCodeMapping
select h.invoiceNumber invoice_number, h.customerNumber customer_number, h.fseInvoiceDate invoice_date, d.manufacturerSKU sku, d.invoice_qty cases, d.totalNetWeight lbs, d.extendedPrice dollars
from tbL_IMPORT_JMS_600_invoice_header h
inner join tbl_IMPORT_JMS_610_invoice_detail d
on d.fseHeaderbatchId = h.eai_batchId
and d.ownerId = h.ownerId
and d.ownerType = h.ownerType
and d.fseHeaderLineNumber = h.eai_lineNUmber
where d.eai_batchId in ( ( select batchId from tbl_EAI_inboundBatches where batchId = or parentBatchId = ) )
order by invoice_number
insert into tbl_IMPORT_InvoiceHistory (
ownerId, ownerType, eai_batchId, eai_lineNumber,
customer_number, sku, invoice_date, invoice_number, unit_of_sale, case_qty, extended_price, lb_qty
) values (
1984, 'MFR', , ,
,
,
,
,
'CSE',
,
,
)