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 = 'Y' and operatorType != 'UNIT' and choId = and 1 = 2 and choId = and ( operatorName like or choId = ) and ( 1 = 2 or choId in ( ) ) order by operatorName for json auto, include_null_values