CFF KB - Carrz-Fox-Fire Promotions Knowledge Base
CFF KB is all about 1 thing: The Sharing of Knowledge and the Power we gain from it.Knowledge Base
- Breadrumbs:
The ORDER BY clause is invalid in views
- Article ID:
7269 - Date Created
Friday, March 1, 2024 - This Article Has been Viewed
305 times - Short Desc
You may receive an error when creating a View with a SQL query. The ORDER BY clause is invalid in views. - Details
You must use the TOP Clause when creating a SQL Query in SSMS View. When using the ORDER BY Clause, if not, you will receive the following error.Msg 1033, Level 15, State 1, Procedure Header_AlbumSales, Line 3 [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. - Recreate Issue
You will receive this error when creating the new VIEW with the following code.
Create View MyViewName_Here
as
Select Col2 from Table1 where Col1=1 order by Col1 Desc
Even though this code will run in SSMS and will run on your website, it will not work in VIEW. - Resolve Issue
In most cases, you will have to use a TOP Clause to add the Query to SSMS View when using a Group By.
Create View MyViewName_Here
as
Select Top 1 Col2 from Table1 where Col1=1 order by Col1 Desc
Having TOP 1, or whatever number you need, will allow the code to run in VIEW.
Share With Friends (Updated 6-8-2010)
Recent Articles
All Topics
- Coming Soon - Knowledge Exchange
Trending Articles
- Microsoft VBScript runtime error '800a0046' Permission denied FileSystemObject 24694
- Microsoft OLE DB Provider for SQL Server error '80040e57' String or binary data would be truncated. or The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data. 21297
- ADODB.Parameters error '800a0e7c' Parameter object is improperly defined 19544
- After Effects warning: Audio conforming failed for the following file .cfa. Perhaps due to disk space 17785
- The backup set holds a backup of a database other than the existing 16825