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 |
|
Geo
Starting Member
9 Posts |
Posted - 2002-01-11 : 03:49:52
|
| hi everybody,I wrote a little function which orders my table by ID, movelast, and finally memorizes the ID of the last record in a variable.The problem is SQL, with the movelast, positions the cursur on the phisycal last record and not on the logical one!Infact, my table orders the ID in this way:----------------------234...100101102..110...etc...-----------------------so SQL will memorize -10- as last record (the physical one)but i need -102- that is the logical record, the last that has been inserted!!!Can any of you help me? |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-01-11 : 09:09:57
|
by the Data it looks your last record will be the Maximum Id.Cant you do it this waySelect Max(id) from tablenamequote: The problem is SQL, with the movelast, positions the cursur on the phisycal last record and not on the logical one!
if you dont sort your cursor(AVOID IT) you will get the data in the order in which you have inserted.HTH----------------------------Anything that Doesn't Kills you Makes you Stronger |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-01-11 : 10:58:26
|
| >> you will get the data in the order in which you have inserted.Unless pages have been split, you have a clustered index or this time the server has just decided the query would be better served by a different plan.==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2002-01-11 : 17:31:22
|
| And of the possibility that what you're really trying to do is find out the value of the IDENTITY field for the record that you just inserted, then instead of all that, just do a SELECT @varname = @@IDENTITY.--------------------------------There's a new General in town... |
 |
|
|
|
|
|
|
|