CREATE TABLE TestTable ( ID int, Name VARCHAR(100), Salary int)
--Create view with ORDER BY
CREATE VIEW vw_ViewTest
AS
SELECT * FROM TestTable ORDER BY ID DESC
GO
The error message is as follows:
Msg 1033, Level 15, State 1, Procedure vw_ViewTest, Line 3
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.
-- To avoid this error, remove ORDER BY clause while creating View
CREATE VIEW vw_ViewTest
AS
SELECT * FROM TestTable
GO
-- Clean up code
DROP TABLE TestTable
DROP View vw_ViewTest