ROWNUM [ PL/SQL ] Analog for T-SQL
There is no ROWNUM Analog in T-SQL. ROWNUM is used in PL/SQL to to get the number of rows the query returns in the same query. There is no easy way to perform the same trick in T-SQL query. Small snippet below demonstrates the easy way to achieve the same goal using inner view.
SELECT (SELECT SUM(1) FROM employee t1 WHERE t1.emp_id <= t2.emp_id) AS rownum, t2.* FROM employee t2
Use in small tables only, since it is not performant on large databases.
Monday, January 19, 2004 7:39 AM