declare @ownerId int = ; declare @ownerType varchar(3) = ; with methods as ( select methodCode, methodName, active, sortRank from tbl_crm_interactionMethods with (nolock) where ownerid = and ownertype = ) #forJSON( 'methods', attributes.datastore, 'sortRank,methodName' )#