How to get the previous row from a defined row.

For example you have a student table and you would like to see the record of a student  who have previous record row from student  id  12.
For this the query is:


DECLARE @intStudentID int=12

SELECT top 1 * from STUDENT A WHERE A. intStudentID  < @intStudentID  order by 1 desc


Comments

Popular posts from this blog

TSQL To Get All the Names of tables and Databases whose data have changed in last 24 Hours

To Get All the Names of tables and Databases their data have changed in last 24 Hours And Backup those databases

Apply paging in procedure