What is the most efficient way to read the last row with SQL Server?
The table is indexed on a unique key -- the \"bottom\" key values represent the last row.
I tried using last in sql query in SQl server 2008 but it gives this err: " 'last' is not a recognized built-in function name."
So I ended up using :
select max(WorkflowStateStatusId) from WorkflowStateStatus
to get the Id of the last row. One could also use
Declare @i int
set @i=1
select WorkflowStateStatusId from Workflow.WorkflowStateStatus
where WorkflowStateStatusId not in (select top (
(select count(*) from Workflow.WorkflowStateStatus) - @i ) WorkflowStateStatusId from .WorkflowStateStatus)