declare @ownerId int = ; declare @ownerType varchar(3) = ; with relationshipRanks as ( select cast( selectionValue as int ) caRelationshipRank, selectionLabel caRelationshipRankText, sortRank from tbl_FSPRO_FieldLookups rr with (nolock) where rr.ownerId = @ownerId and rr.ownerType = @ownerType and rr.fieldName = 'RelationshipRank' ) #forJSON( 'relationshipRanks', attributes.datastore, 'sortRank' )#