I'd recommend using the IDENT_CURRENT function. However it is limited to one table. So if you're looking for the last entered id across all tables...well it's a bit more complex. Unless you use some kind of scheme that identifies what table an ID belongs too. I've seen this used at companies where they have a single generator for all IDs. But I digress.
Select * from table_name where id=IDENT_CURRENT('table_name')
> the LAST record entered in the database.... if for example if you
> entered 10 records in a new database, how do you fetch #10 - or the LAST
> recorded
> entered (without indicating 'get the 10th record')
Again, SQL Server doesn't keep track of which row is the newest. This is
not Access, and you are not stuffing a line of data at the end of a text
file.
What does your table structure look like Do you have a naturally
increasing column (such as IDENTITY, or DATETIME reflecting when the row was
created)
A
What does "last" mean A table is an unordered set of rows, so you need to
indicate to SQL Server what you mean by "last"...
wrote in message
news:c6e41dc5-463e-4bfd-b88c-99ebbc38e746@discussions.microsoft.com...
> Don't know if this is the right SQL section, but... using VBE, how do
> you SQL for the last record in the database
>
> Thanks.
>
> the LAST record entered in the database.... if for example if you
> entered 10 records in a new database, how do you fetch #10 - or the LAST
> recorded
> entered (without indicating 'get the 10th record')
Again, SQL Server doesn't keep track of which row is the newest. This is
not Access, and you are not stuffing a line of data at the end of a text
file.
What does your table structure look like Do you have a naturally
increasing column (such as IDENTITY, or DATETIME reflecting when the row was
created)
A
the LAST record entered in the database.... if for example if you entered 10 records in a new database, how do you fetch #10 - or the LAST recorded entered (without indicating 'get the 10th record')
Your reply has helped me a lot !!!! I have been searching for this answer since a long time and didn't get any answer from any where !!!!I am extremely thankful to you.
Get last record in a SQL database
Vishal Verma
I'd recommend using the IDENT_CURRENT function. However it is limited to one table. So if you're looking for the last entered id across all tables...well it's a bit more complex. Unless you use some kind of scheme that identifies what table an ID belongs too. I've seen this used at companies where they have a single generator for all IDs. But I digress.
Select * from table_name where id=IDENT_CURRENT('table_name')
Should do what you want.
David NL
T. J. Bussler
Ghalib
rlieving
Rick112
Javier Carvajal
entered (without indicating 'get the 10th record')
Andrey Egorov
SELECT MAX id but wasn't sure if there was a better way of doing so.
Jamie Cool
CraigSBoyd
SELECT *
FROM TABLE
WHERE ID = IDENT_CURRENT('TABLE')
or
SELECT *
FROM TABLE
WHERE ID = (SELECT MAX(ID) FROM TABLE)
I hope this helps.
Sincerely,
Edward E. Weller
Jeff Micro
isn't is what you're asking for
Sebastien
athanks to all fo royu help I got it
bmkiss67
Dear Valeriy,
Your reply has helped me a lot !!!! I have been searching for this answer since a long time and didn't get any answer from any where !!!!I am extremely thankful to you.
May God Bless you always
Thanks
Maleeha
JeffWoodard
able to open the database... so I'm reading a book.