Sunday, 5 August 2012

how to get last record value in sql server without using MAX/TOP clause?


1)SELECT * FROM  tablename WHERE  primarykeyid= IDENT_CURRENT('tablename')

Eg:
SELECT * FROM  tbl_emp WHERE  empid= IDENT_CURRENT('tbl_emp ')

2)
set rowcount 1 
select * from  tbl_emp order by empid desc

SET ROWCOUNT { number | @number_var } 
Causes SQL Server to stop processing the query after the specified number of 
rows are returned.

No comments:

Post a Comment