with distributors as ( select cdr.cdr_recordId, cdr.cdr_dstName, cdr.cdr_dstCompanyType, dst.dstId, dst.dstName, cdr.cdr_dstCode, coalesce( cdr.cdr_dstCode, '' ) + ' - ' + cdr.cdr_dstName as cdr_dstName_dstCode, cdr.crmActive from tbl_CDR_Distributors cdr with (nolock) left outer join tbl_DST_Distributors dst with (nolock) on dst.dstId = cdr.fsl_dstId where cdr.ownerId = and cdr.fsl_tablecode = ) #forJSON( 'distributors', attributes.datastore, 'cdr_dstName' )# 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 --->