Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi.
I would like to retrieve the latest inserted or even updated identity from a table.but whenever i write the following code there is no results at all.

SQL
select * from PersonHowEducation prh inner join HowzeEducation he on 
              prh.HowzeEducationId=he.HowzeEducationId
              where he.HowzeEducationId=@@IDENTITY


what shall i realy do ?
Posted

U may try the SCOPE_IDENTITY which is purposed for exactly wat u want
 
Share this answer
 
In this case @@IDENTITY is not going to help you. To this job you need to add a column in the table named LastUpdatedDate with the Default Constraint of Current DateTime. While updating the table, you can update this column also. Then easily you can write select query based on that. Like this:
SQL
SELECT * FROM PersonHowEducation prh INNER JOIN HowzeEducation he ON
prh.HowzeEducationId=he.HowzeEducationId ORDER BY he.LastUpdatedDate DESC


This will give you a list of updated records in descending order of LastUpdatedDate column. You can customize the query according to your wish.


--Amit
 
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