Given a SQL Server table (Table1) and view (View1) defined as SELECT * FROM Table1
What is the best way to add a column containing an index value (eg 1,2,3,...n) for each row?
The result would be something like...
Where the first column in the bullet list above is calculated/computed in the view.
Probably the simplest is row_number()
:
select row_number() over (order by (select null)) as index_value,
. . .
. . .
If you have a particular ordering in mind, you can use that logic instead of (select null)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.