SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Adding Sorts to SQL Server Views

By iecdba,

Total article views: 198 | Views in the last 30 days: 2

Microsoft says that you cannot add an ORDER BY to a view unless it comes with a TOP clause at the beginning of the query. Many people think that if that's true then you cannot "Order" the whole query but only the top few. However, this is not true because when you use TOP 100 PERCENT with the query you can ORDER BY the whole result set inside the view definition, like this (I tested this on a NT4 workstation and on NT4 server SP6, with SQL Server versions 7 and 2000):

By iecdba,

Total article views: 198 | Views in the last 30 days: 2
Your response
 
 
Related Articles
FORUM

Query performance for Ordering

Query performance for Ordering

FORUM

query execution order

query execution order

FORUM

Query Order

while run the query the order of data will be different in every run.

FORUM

Query is slow because of TOP and Order By Count(*)

How to speed up query with TOP and Order By?

FORUM

MDX query using ORDER and UNION functions

Having trouble using the ORDER function in an MDX query that uses a UNION

Tags
miscellaneous    
t-sql aids    
 
Contribute

Free registration required...

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Login (existing users)

Login

Email:   Password:   Remember me: Forgotten your password?

Register (new users)

Register

Email:   Password:
Confirm:

Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

Steve Jones
Editor, SQLServerCentral.com