Click here to Skip to main content
15,917,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am executing an update query in a table and i have to return the ID of that row i updated.. How can i get that.. IF i use IDENT_CURRENT('tbl') it returns the last id of that table , so i can't use that...Can anyone pls help me
Posted

1 solution

You need to add a date field to the table and add a trigger to update it.
SQL
CREATE TRIGGER LastChangedOnTbl on Tbl
FOR UPDATE, INSERT AS
UPDATE dbo.Tbl
SET LastUpdate = GetDate()
WHERE id IN (SELECT id FROM inserted)

You can then use this field to select the most recently updated row.

Good luck!
 
Share this answer
 
Comments
Arjun Menon U.K 13-Jul-12 6:39am    
Let me try..Thanks anyways

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