with operators as ( select distinct choId, operatorName, beneficiary, operatorType, cast( case when hasSubGroups = 'true' then 1 else 0 end as bit ) hasSubGroups, cast( case when locationLevelPurchasing = 'Y' then 1 else 0 end as bit ) locationLevelPurchasing, case when beneficiary = 'Y' then 1 else 0 end hasAgreements from tbl_DW_1fsOperators#_tableSuffix# o with (nolock) where ownerId = and ownerType = and purchasing = and operatorType != 'UNIT' ) #forJSON( 'operators', attributes.datastore, 'operatorName' )#