I have a SQL server 2008 table with the folling data in it:
seq | item
1 | A
2 | B
3 | C
4 | C
5 | C
6 | B
7 | D
8 | D
9 | C
I what return a new column which is a number which increments on change of item, as follows:
seq | item | Seq2
1 | A | 1
2 | B | 2
3 | C | 3
4 | C | 3
5 | C | 3
6 | B | 4
7 | D | 5
8 | D | 5
9 | C | 6
The initial sequence must be maintained. Hope you can help, Tim
Edit:
I don’t what to update the table, just return the result set via a view or query. Thanks for all your efforts.
Update
A version where seq is a datetime. I have added an extra CTE that enumerates the rows ordered by seq.