My requirement like this:
I have to fetch a row from table “A”. Now I have to loop through all the rows and get the values from the ID column. If I get ID = 5 then I want to execute some stored procedure through which I get the previous id row from some table “B”. Like
select * from table b where ID = 4
Buy my question is: if someone deleted that row from the database (e.g. some user deleted the rows with id 3 and 4) – then how can I get the row with id = 2 from the database?
Please give me some sql stored procedure to get previous id record from table.
The following query should get it for you:
@YourIDis a variable containing your recently inserted ID