In MySQL you are allowed to do something like this
SELECT @n := @n + 1 n,
first_name,
last_name
FROM table1, (SELECT @n := 0) m
ORDER BY first_name, last_name
*(Codeblock was originally taken from https://stackoverflow.com/a/16555527/2279200)
Is there any equivalent approach in Oracle or SQL Server
Note:
Something similar can be done with
update
in SQL Server, but I am asking if it can be done with select.Using
row_number
is not an option, since I want to handle how the values of @n are changing.I am aware that SQL Server disallows having both temp variables and table column in select statement.