#attributes.dataStore.sqlOrderBy#order by #listFirst( _columnList )# with batches as ( select b.ownerId, b.ownerType, convert( varchar, b.ownerId ) + ':' + b.ownerType as clientCode, b.batchId, b.batchClass, b.batchTime, b.status, b.message, b.fileFormat, b.fileProcessor, b.fileName, b.runSeconds, b.startTime, floor( 10191817 * sqrt( b.batchId * log10( b.batchId ))) as batchTk, ( select count(*) from tbl_EAI_ChildBatches cbl with (nolock) where cbl.ownerId = b.ownerId and cbl.ownerType = b.ownerType and cbl.batchId = b.batchId ) childBatchCount, cast( b.batchTime as date ) batchDate from tbl_EAI_inboundBatches b with (nolock) inner join tbl_EAI_ChildBatches cb with (nolock) on cb.childBatchId = b.batchId and cb.batchId = where b.ownerId = and b.ownerType = ), batches2 as ( select batches.*, b.broker_name as clientName from batches inner join tblBrokers b with (nolock) on b.broker_id = batches.ownerId where batches.ownerType = 'BRO' union all select batches.*, m.mfr_name as clientName from batches inner join tblManufacturers m with (nolock) on m.mfr_id = batches.ownerId where batches.ownerType = 'MFR' union all select batches.*, d.dstName as clientName from batches inner join tbl_DST_Distributors d with (nolock) on d.dstId = batches.ownerId where batches.ownerType = 'DST' union all select batches.*, c.cho_name as clientName from batches inner join tbl_CHO_Operators c with (nolock) on c.cho_id = batches.ownerId where batches.ownerType = 'CHO' union all select batches.*, f.company as clientName from batches inner join tbl_MSC_FSLibraryUsers f with (nolock) on f.userid = batches.ownerId where batches.ownerType = 'MSC' ) select count(*) over() as fseRowCount, lag( batchId ) over( #_orderBy# ) as previousBatchId, lead( batchId ) over( #_orderBy# ) as nextBatchId, #_columnList# from batches2 where #applyFilter( attributes.dataStore.filter )# #_orderBy# offset #attributes.dataStore.skip# rows fetch next #attributes.dataStore.take# rows only for json path, include_null_values