Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Equivalent Oracle Rownum Pseudo Column in SQL Server

Status
Not open for further replies.

Edd01

Programmer
Jan 7, 2003
1
GB
I am having trouble finding an equivalent SQL Server statement for the following Oracle Statement:

SELECT COL1, COL2 FROM MYTABLE WHERE ROWNUM < 10

The ROWNUM Psuedo column in Oracle would output the Row number of each row in the query and hence only the top 10 rows would be shown for this query.

I am using SQL Server 6.5
I have tried using the SELECT TOP n statement but it appears not to be supported in my version.

Is there an Equivalent to the ROWNUM column or do the later versions of SQL Server support TOP?

Thanks

Edwin Derrick

 
ROWNUM is an Oracle thing. The ANSI standard for SQL is that rows in a table have no intrinsic order.

SELECT TOP n should work in 6.5:

SELECT TOP 10 COL1, COL2 FROM MYTABLE
 
TOP was not implemented in SQL Server until version 7. You can use SET ROWCOUNT in SQL 6.5. The following will restrict the number of rows to 10.

/* Set the rowcount to 10*/
SET ROWCOUNT 10

Select * From Table

/* Reset the rowcount to unlimited*/
SET RWOCOUNT 0 Terry L. Broadbent - DBA
SQL Server Page:
If you want to get the best answer for your question read faq183-874.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top