with parentDistributors as ( SELECT d.dstid AS dstid, cdr.cdr_dstname as companyName 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 cdr.cdr_dstcompanytype = 'P' ) #forJSON( 'parentDistributors', attributes.dataStore, 'companyName' )#