Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2001-12-18 : 09:18:04
|
| Niru writes "Hi, I would like to create a view which will have all the fields from a table & an additional column which will have an autoincremented number. This additional column is to be created in the view & does not exist in the table.The purpose of creating this view is to fetch records for a particular range of values in the autoincremented column which will help in paging records in ASP. I could have achived this if I had an identity column in the table itself but my table does not have an identity column.Could you please guide me.Thanks in advance.Niru." |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2001-12-18 : 09:59:50
|
| Have you read this article?http://www.sqlteam.com/item.asp?ItemID=1491You can search SQL Team for "increment" or "sequence" or "sequential" and you'll get a few other hits, one of them is bound to work for you. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2001-12-18 : 10:05:45
|
| You will need to have an rder by clause for the sequence to be meaningful which means that you also need to have top 100 percent to allow this in the view so (an identity column on the source table doesn't actually make any difference).select top 100 percent *, seq = (select count(*) from tbl t1 where fld <= t1.fld)from tblorder by fldThe fld (or combination) will need to be unique for this to give distinct sequence nos.==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|