I have the following query:declare @counter intset @counter = 0UPDATE Attribute_header SET @counter = HeaderOrder = @counter + 1Where headerID IN ( SELECT distinct p.headerid FROM attribute_header p WHERE Headeryearend > 2003)
Example of the records are:HeaderID HeaderYearEnd HeaderOrder1 2005 22 2005 13 2005 34 2003 -5 2005 4If a transaction leads to deleting the 3rd record, then I have the following Records:HeaderID HeaderYearEnd HeaderOrder1 2005 22 2005 14 2003 -5 2005 4
The way I want the query to update the records is (maintain the previous order as far as it is continuous and push the records up when a particular HeaderOrder is missing; i.e, change the HeaderOrder for record HeaderID=5 from 4 to 3):HeaderID HeaderYearEnd HeaderOrder1 2005 22 2005 14 2003 -5 2005 3It occured to me to put 'Order By HeaderOrder' at the end of the Select statement, but the query doesnot let me 'Order by HeaderOrder' since it is an Update statement. How Do I achieve this?
Thank you.PKS.