#attributes.dataStore.sqlOrderBy#order by #listFirst( _columnList )# with data as ( select cast ( null as int ) operatorSegmentId, mainSegment as operatorSegment, string_agg( segmentId, ',' ) operatorSegmentIds from tbl_OPR_Segments ms with (nolock) group by mainSegment union all select distinct segmentId as operatorSegmentId, operatorSegment, cast( segmentId as varchar) operatorSegmentIds from tbl_OPR_Segments with (nolock) ) select count(*) over() as fseRowCount, #_columnList# from data where operatorSegmentId = operatorSegment = #applyFilter( attributes.dataStore.filter )# #_orderBy# offset #attributes.dataStore.skip# rows fetch next #attributes.dataStore.take# rows only for JSON AUTO, INCLUDE_NULL_VALUES