Tuesday 13 November 2012

Procedure to get Last Row for Non-Identity tables

I had an situation where i want to get the last row for Non_Identity Table.
Then i used this query to get the last row inserted into the table.




DECLARE GETLAST CURSOR DYNAMIC FOR 
SELECT [ColumnName] FROM [dbo].[TableName]

OPEN GETLAST

FETCH LAST FROM GETLAST

CLOSE GETLAST

DEALLOCATE GETLAST

Below screenshoot will explain


No comments:

Post a Comment