🙂
Is there any way to create an index, and incrementing with a given condition, but without CURSOR handling/usage
For example:

The condition in my case is that: “if the current color (this is the item to be checked) is the same as the last one: not increment, otherwise increment in one unit”
This must be in a SQL query with no CURSOR USAGE and of course a good time (work with … 10000 rows at least)
Thanks in advance.
EDIT: I forgot to mention that NEW_INDEX Column doesn’t exist. It must be generated with the with the query.
EDIT2: Is there a way that only make use of SELECT/INSERT/UPDATE statements? (not set, declare…)
Assume a table called Colors with fields
ID,Color, andColorIndexof typesint,varchar, andintrespectively. I also assume the OP means prev / after based on an ordering of theIDfield inascorder.You could do this without a cursor, and use a while loop…but it definately isn’t set based:
The result after execution:
Performance wasn’t too shabby as long as ID and color are indexed. The plus side is it is a bit faster then using a regular old CURSOR and it’s not as evil. Solution supports SQL 2000, 2005, and 2008 (being that you are using SQL 2000 which did not support CTEs).