Anatoly Lubarsky Logo
MSSQL, .NET, Design. Life and Music

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.


Related Posts:

Monday, January 19, 2004 7:39 AM

If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish.

Post a Comment

Protected by CAPTCHAEnter the code you see
Name (*)  
E-mail (*)  
Url
Remember

Comment (*)