Click here to Skip to main content
12,755,080 members (41,766 online)
Rate this:
Please Sign up or sign in to vote.
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 GridView , so can i apply this query in Function and then call this function by sroted procedure and then use it in connection?

i am also using SqlServer2008r2,

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

Solution 1

U should try like that :

-- After inserting data in your table
CandidateID =@@IDENTITY -- it will return last inserted id

then in front end u can use OutPut Parameter for getting this value.
Rate this: bad
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[^]

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2017
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