Tuesday, August 18, 2020

Create a view with ORDER BY clause

 Msg 1033, Level 15, State 1, Procedure xxxx , Line 105 [Batch Start Line 0]

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.



As the error message suggested use


SELECT TOP 9999999  "fromYourQuery" ORDER BY something

Recently Executed queries

 SELECT     txt.TEXT AS [SQL Statement],     qs.EXECUTION_COUNT [No. Times Executed],     qs.LAST_EXECUTION_TIME AS [Last Time Executed],   ...