Normaly if we use ORDER BY clause in a view we'll get the following error
Error : The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.
Inspite of this if we want to use ORDER BY clause in a view, consider using the following method
USE pubs GO
CREATE VIEW AuthorsByName AS SELECT TOP 100 * FROM authors ORDER BY City GO
The TOP construct is most useful when you combine it with the ORDER BY clause. The only time that SQL Server supports an ORDER BY clause in a view is when it's used in conjunction with the TOP keyword.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|