This should do it, but be careful with the delete at the end.Create Table #myTable (name varchar(10), Qual varchar(10), notes varchar(100), allNotes varchar(100))Insert Into #myTable (name, Qual, notes)Select 'Simon', 'spanish', 'Distinction' UnionSelect 'Simon', 'spanish', 'Pass' UnionSelect 'Simon', 'german', 'A Level' UnionSelect 'Stewart', 'spanish', 'Degree' UnionSelect 'Stewart', 'spanish', '2:1' UnionSelect 'Martin', 'english', 'A level'Select * From #myTableDeclare @curKey varchar(100), @Notes varchar(100)Update #myTableSet @Notes = case when isnull(@curKey,'')<>name+'|'+Qual then notes else @notes + ', ' + notes end, @curKey = name+'|'+Qual, AllNotes = @notesFrom #myTableDelete AFrom #myTable AWhere len(Allnotes)<(Select max(len(Allnotes)) From #myTable B Where name = A.name and Qual = A.Qual)Select * From #myTableDrop Table #myTable
Corey
Secret Service Agent: Mr. President, you're urinating on me.President Lyndon Johnson: I know I am. It's my prerogative.