how i write stored procedure to get last record of the table
It is ok if it is the primery key of the table
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Sep 10, 2013, 2:55 AM
hi,
when you want to get last record of the table?
is it just after newly inserted record or any thing else?
can please share your table structure?
Suthish NairPosted Sep 10, 2013, 8:14 AM
Suthish NairPosted Sep 10, 2013, 4:48 AM
CREATE TABLE [dbo].[Test]
(
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](50) NULL
)
--select * from Test
insert into Test (Name) VALUES ('A')
select * from Test where ID = @@IDENTITY
insert into Test (Name) VALUES ('B')
select * from Test where ID = SCOPE_IDENTITY()
insert into Test (Name) VALUES ('C')
select * from Test where ID = IDENT_CURRENT('Test')
Sanjeeb LenkaPosted Sep 10, 2013, 12:24 AM
If your SQL Server table has a column of type
INT IDENTITY(orBIGINT IDENTITY), then you can get the latest inserted value using:SELECT SCOPE_IDENTITY()
Joxin StanlyPosted Sep 9, 2013, 11:30 AM
please have a look @ below link..
http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/
hope this helps