Click here to Skip to main content
13,053,994 members (91,943 online)
Rate this:
Please Sign up or sign in to vote.
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.

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

what shall i realy do ?
Posted 5-Oct-12 19:37pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:
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.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

U may try the SCOPE_IDENTITY which is purposed for exactly wat u want

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.170713.1 | Last Updated 8 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