Maybe something like this:declare @meta table( caseFormID int, fieldName varchar(30), fieldValue varchar(30), caseFormDataID int)insert @metaselect '123456', 'Name' , 'John' , 987654 union allselect '123456', 'NameAdd_0' , 'Fred' , 987656 union allselect '123456', 'Relationship' , 'Grandchild' , 987655 union allselect '123456', 'RelationshipAdd_0' , 'Nephew' , 987657 union allselect '123456', 'CaseName' , 'Alpha' , 987612 union allselect '123456', 'CaseDate' , '2014-08-21' , 987613 union allselect '123789', 'Name' , 'Daisy' , 951753 union allselect '123789', 'Relationship' , 'Grandchild' , 951754 union allselect '123789', 'CaseName' , 'Beta' , 951755 union allselect '123789', 'CaseDate' , '2014-08-21' , 951756;--field mappingsdeclare @fieldRootName table ( fieldName varchar(30) not null primary Key)insert @fieldRootName select 'Name' union all select 'Relationship';--resultselect m1.caseFormID, m1.fieldValue as CaseName, m2.fieldValue as CaseDate, m3.fieldValue as Name, m4.fieldValue as Relationshipfrom @meta m1 left join @meta m2 on m2.caseFormID = m1.caseFormID left join @meta m3 on m3.caseFormID = m1.caseFormID left join @meta m4 on m4.caseFormID = m1.caseFormID left join @fieldRootName rName on m3.fieldName LIKE rName.fieldName + '%' left join @fieldRootName rRelationship on m4.fieldName LIKE rRelationship.fieldName + '%'where m1.fieldName = 'CaseName' and m2.fieldName = 'CaseDate' and m3.fieldName LIKE 'Name%' and m4.fieldName LIKE 'Relationship%' and REPLACE(m3.fieldName,rName.fieldName,'') = REPLACE(m4.fieldName,rRelationship.fieldName,'');