ARR Asked: 2020-04-06 12:49:34 +0800 CST 2020-04-06 12:49:34 +0800 CST 2020-04-06 12:49:34 +0800 CST Add Positions Column SQL Server 2012 772 I have the following code: SELECT TERRITORIAL, REGIONAL, TOTAL, 1 AS POSICION FROM AR_TEST My result is: What I need to do is make the position column increment + 1 to get the position number of the region. sql 2 Answers Voted Best Answer Luciano Montañez 2020-04-06T12:53:52+08:002020-04-06T12:53:52+08:00 You could use ROW_NUMBER . Edited, as @Lamak comments, it would change the order, so we change theorder by SELECT TERRITORIAL, REGIONAL, TOTAL, ROW_NUMBER() OVER (ORDER BY (select 0)) AS POSICION FROM AR_TEST It should be compatible with sql server2008+ Marlon Mejía 2020-04-06T12:59:22+08:002020-04-06T12:59:22+08:00 SELECT TERRITORIAL, REGIONAL, TOTAL, ROW_NUMBER() OVER (ORDER BY REGIONAL) as POSICION FROM AR_TEST
You could use ROW_NUMBER .
Edited, as @Lamak comments, it would change the order, so we change the
order by
It should be compatible with sql server
2008+