select distinct bat.batchId, bat.fileFormat, bat.batchTime, bat.fileName from tbl_EAI_InboundBatches bat with (nolock) inner join tbl_IMPORT_Distributors fs with (nolock) on bat.batchId = fs.eai_batchId and bat.ownerId= fs.ownerId and bat.ownerType = fs.ownerType where bat.ownerId = and bat.ownerType = and bat.fileFormat = 'DISTRIBUTORS_TXT' and bat.status = 'OK' order by bat.batchTime desc FOR json path, include_null_values