Question : ROW_NUMBER without ORDER BY

Hi Experts,

I use this expression to enable paging in Asp.Net 2.0:
SELECT       TOP (@startRowIndex + @maximumRows)  ROW_NUMBER() OVER (ORDER BY Type) AS RowNum,  Type FROM ...

The problem is I don't want to  reorder my query, I try:
SELECT       TOP (@startRowIndex + @maximumRows)  ROW_NUMBER() OVER (ORDER BY NULL) AS RowNum,  Type FROM ...
But that doesn't work.

My types are : User, Company,  Employee...  because I select Users from UsersTable, Companies from CompanyTable and Employees from EmployeeTable.
I want the resultset to be order like this :  User, Company,  Employee.

As ROW_NUMBER cannot run without ORDER BY (don't know why ??!!!), this causes me troubles.

Thanks in advance for your help.

Answer : ROW_NUMBER without ORDER BY

no direct way, you could try adding a dummy column with a constant value and use that query as derived table, something like this

select row_number() over(order by dummy), * from
(Select 1 dummy, * from tablename) a

or

select row_number() over(order by dummy), * from
(Select 1 dummy) A, tablename
Random Solutions  
 
programming4us programming4us