SQLTeam.com | Weblogs | Forums

Increment value based on next row comparsion

Hi
I am using store procedure that generate report from various table, the problem is ,i have to give number for a ceratin values in column. The line column should check the num row , if the current row and next row values same then increment the line column. or any other methods also welcome.
num | total | line
AB01 | 77 | 1
AB01 | 77 | 2
AB01 | 77 | 3
CC02 | 123 | 1
DC03 | 33 | 1

Select
(cast(num.customer + id) as num,
num.total
line->?
from customertable as num

SELECT num.customer, num.total, 
    ROW_NUMBER() OVER(PARTITION BY num.customer ORDER BY num.customer) AS line
FROM customertable AS num
ORDER BY num.customer
1 Like