If the results in the temporary table is sorted with client hash and ID column is identity, use this-- prepare test datadeclare @tmp table (ID int, ClientHash varchar(3), SeqNumber int, Field1 varchar(3), Field2 varchar(3))insert @tmpselect 1, 'xxx', null, 'a', 'b' union allselect 2, 'xxx', null, 'aa', 'bb' union allselect 3, 'xxx', null, 'aaa', 'bbb' union allselect 4, 'yyy', null, 'c', 'c' union allselect 5, 'yyy', null, 'd', 'd' union allselect 6, 'zzz', null, 'e', 'e'select * From @tmp-- do the workupdate tset t.seqnumber = 1 + t.id - q.mfrom @tmp tinner join ( select clienthash, min(id) m from @tmp group by clienthash ) q on q.clienthash = t.clienthash select * From @tmp
Peter LarssonHelsingborg, Sweden