Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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.
 
Share this answer
 
You have to use @@identity.
SELECT @@IDENTITY will give you the last record

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900