February 8, 2010 at 8:57 am
how i will get latest record from table in sql server 2000,2005
February 8, 2010 at 9:24 am
Does the table have a date stamp column? Or something that would indicate a time or a date of when the row was inserted?
If not, then you may be the last row by selecting the MAX(RowID), if you have this data type set as an integer, and it is set to auto increment by 1 each insert. But this is not a guarantee.
Andrew SQLDBA
February 10, 2010 at 12:01 am
thummalalavanya (2/8/2010)
how i will get latest record from table in sql server 2000,2005
Hi thummalalavanya,
It would really help if you have sample sql create scripts and data for us to better understand what are you trying to achieve.
Andrew is actually right, you can achieve it using MAX(RowID) or timestamp but it would be nice if we are clearer on what your goal is.
Thanks,
Wendell
February 11, 2010 at 5:05 am
If you have an identity column you could use
SELECT @last_ID = IDENT_CURRENT('my_table_name')
to get the last identity value used, but if that record has been deleted, you would get the wrong answer.
OTOH if you want the value immediately after a new record is inserted, you could use
SELECT @last_ID = SCOPE_IDENTITY()
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply