Sunday, January 13, 2008

simple trick to get position of a record in TSQL

original post: Small T-SQL trick
Suppose you have some table id and you want to know the row number of that id. Since there were deletes you can not rely on this field even it is an identity field. So here it goes:
select sum(1) from employee where emp_id <= @my_id

No comments: