I have the following scripts that renumber a column based on the sort order of another column. it also allows for a starting number so I can get a TOP(n) number of records on top of the list and then sort the reamining items in alphabetical order.
I am trying to figure out why sometimes it does not order the result correctly. for Example, it puts "Lancia" after "Landrover". I am suspecting that the "where t2.make < t.make) is not returning the correct result and it causing this to happen.
If there is better/simpler way to do this, I would appreciate any input.
Make is a varchar(50)
OrderNumber is an int
DECLARE @StartingNumber integer
set @startingnumber = 6
set t.ordernumber = (select count(1) from MakeTable t2 where t2.Make < t.Make) + @startingnumber
From makesandmodels t
WHERE t.OrderNumber > 7