with distributors as ( select cdr_recordId, cdr_dstName from tbl_CDR_Distributors with (nolock) where ownerId = and fsl_tablecode = and cdr_dstCompanyType = 'B' ), distributorsFormatted as ( select * ,[#attributes.datastore.map[_mc]#] as [#_mc#] from distributors ) select *, count(*) over() as fseRowCount from distributorsFormatted where #applyFilter( attributes.datastore.filter )# #attributes.datastore.sqlOrderBy#order by cdr_dstName offset #attributes.datastore.skip# rows fetch next #attributes.datastore.take# rows only for JSON PATH, INCLUDE_NULL_VALUES