Just like in sub queries, you can‘t use ORDER BY
in a view definition in sql server unless you also use TOP
.
The reason for this is that Views are acted upon as if they where tables, and tables in sql server (in fact, in any relational database) are considered as not ordered sets.
Just like there is no meaning to the order of records stored in a table,
there is also no meaning to the order of records fetched by a view.
You can use a dirty hack and write SELECT TOP 100 PERCENT ...
and then use ORDER BY
, but I doubt if it has any meaning at all.
Having said all that, you can of course use ORDER BY
in any query that selects from a view.