Click here to Skip to main content
11,583,532 members (65,472 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server-2008
i have a table known as Persons which is (IdCode :pk, not null ,Identity). now i want to have(select) the last inserted IdCode in the table, how can i do that? ofcourse i have to join one another table to this table and then extract IdCode from both of them

at the end i want to show results in Asp.net GridView , so can i apply this query in Function and then call this function by sroted procedure and then use it in Asp.net connection?

i am also using SqlServer2008r2,

thank's in your advise
Posted 2-Oct-12 22:49pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

U should try like that :


CREATE PROCEDURE SPName
@CandidateID VARCHAR(20) OUTPUT
AS BEGIN
-- After inserting data in your table
CandidateID =@@IDENTITY -- it will return last inserted id
END

then in front end u can use OutPut Parameter for getting this value.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You have to use @@identity.
SELECT @@IDENTITY will give you the last record

Check this
http://msdn.microsoft.com/en-us/library/ms187342.aspx[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 1,523
1 Sergey Alexandrovich Kryukov 995
2 Abhinav S 696
3 Dave Kreskowiak 621
4 Suvendu Shekhar Giri 568


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100