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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 9, 2013, 10:55 PM EDT
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?
Joxin Stanly181 reputationPosted Sep 9, 2013, 7:30 AM EDT
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
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Sep 9, 2013, 8:24 PM EDT
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()
Suthish NairRank #92 · 22.8K reputationPosted Sep 10, 2013, 12:48 AM EDT
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')
Suthish NairRank #92 · 22.8K reputationPosted Sep 10, 2013, 4:14 AM EDT