I am trying to change a tables ordering. Position is the number by which I'm ordering the results. In certain circumstances the natural position and the position set in the db do not match. I am trying to update them to their natural position.I can get the details I want with the following SQL, but how can I do this processing on an UPDATE so I can set the correct positions?SELECT UniqueId, ParentId, Name, Lineage, Position, /* Need to get the row position, Can use ROW_NUMBER in 2005 but we don;t have it :( */ (SELECT COUNT(*) + 1 FROM Page as p2 WHERE LEFT(lineage, LEN(@Lineage)) = @Lineage AND Depth = @Depth AND p2.lineage< p1.lineage ) as NaturalPosition FROM Page as p1 WHERE LEFT(lineage, LEN(@Lineage)) = @Lineage AND Depth = @DepthOrder By Lineage, Position
68 64 Item 1 /160/264/068/ 0 169 64 Item 2 /160/264/069/ 0 270 64 Item 3 /160/264/070/ 0 371 64 Item 4 /160/264/371/ 3 467 64 Item 5 /160/264/567/ 5 592 64 Item 6 /160/264/692/ 6 6