declare @ownerId int = ; declare @ownerType varchar(3) = ; with data as ( select 'OPR:' + cast( classificationId as varchar ) partnerClassificationKey, 'OPR' partnerType, classificationId, abbreviation, name, 'Operator - ' + name as qualifiedName, description, 1 as partnerTypeRank, sortRank from tbl_OPR_Classifications with (nolock) where ownerId = @ownerId and ownerType = @ownerType union all select 'CDR:' + cast( classificationId as varchar ) partnerClassificationKey, 'CDR' partnerType, classificationId, abbreviation, name, 'Distributor - ' + name as qualitfiedName, description, 2 as partnerTypeRank, sortRank from tbl_CDR_Classifications with (nolock) where ownerId = @ownerId and ownerType = @ownerType ) #forJSON( 'data', attributes.datastore, 'partnerTypeRank,sortRank,name' )#