with parentDistributors as ( SELECT cdr.cdr_recordId, cdr.cdr_dstName, d.dstId FROM tbl_CDR_Distributors cdr with (nolock) INNER JOIN tbl_DST_Distributors d with (nolock) ON cdr.FSL_dstid = d.dstid WHERE cdr.OwnerID = AND cdr.FSL_TableCode = AND d.dstCompanyType = 'P' ) #forJSON( 'parentDistributors', attributes.dataStore, 'cdr_dstName' )#