operatorUnits log {ts '2025-02-12 09:09:40'} SQL with data as ( select opr.oprType, opr.operatorId, opr.companyName, opr.address, opr.city, opr.state, opr.zipcode, ter.territoryId, ter.name territoryName, opr.lastInteractionDate, opr.nextInteractionDate, opr.unitNbr, pc.email, pc.firstName, pc.lastName, pc.title, pc.fspro_userid primaryContactUserId, cdr.cdr_dstname, cdr.cdr_recordId distrib1, nullif( opr.oprsegment, 0 ) oprSegment, nullif( opr.cuisineId, 0 ) cuisineId, cast( case when opr.buyingDecisions = 'Y' then 1 else 0 end as bit ) as buyingDecisions, opr.seasonType, opr.seasonOpenDate, opr.seasonCloseDate from tbl_OPR_ClientOperators opr with (nolock) left outer join tbl_FSpro_members pc with (nolock) on pc.orgId = opr.operatorId and pc.orgtype = 'OPR' and pc.ownerId = opr.ownerId and pc.fspro_userid = opr.primaryContactId left outer join tbl_CDR_Distributors cdr with (nolock) on cdr.cdr_recordId = opr.distrib1 and cdr.ownerId = opr.ownerId and cdr.fsl_tablecode = opr.fsltablecode and cdr.crmActive = 'Y' inner join tbl_TER_Territories ter with (nolock) on ter.territoryId = opr.territoryId and ter.ownerId = opr.ownerId and ter.fsl_tablecode = opr.fsltablecode where opr.ownerId = 709 and opr.fsltablecode = 'MFR' and opr.oprcompanytype in ( '0' ) and opr.oprparentco = 10622068 and opr.crmActive = 'Y' ) , data_mappedData as ( select * from data ) , data_preData as ( select * from data_mappedData with (nolock) where ( 1 = 1 ) ) , data_data as ( select * from data_preData ) , data_return as ( select * from data_data where 1 = 1 order by territoryName,state,companyName offset 0 rows fetch next 10000000 rows only ) , data_result as ( select ( select count(*) from data_data ) as totalCount, ( select * from data_return for json auto, include_null_values ) as data ) select * from data_result for JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER