Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error: The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.

Posted on 2004-07-30
5
Medium Priority
?
1,487 Views
Last Modified: 2007-12-19
SELECT MaxDate = MAX(Start_Date), EndDate = MIN(End_Date) FROM Query_Registration where start_date IN (Select Registration_ID, Course_ID, Course_Number, Course_Name, Class_ID, Start_Date, End_Date, User_ID, FName + ' ' + LName AS Name, Company_Name, Address1, Address2, City, State, Zip, Country, CC_Name, Price, Payment_Type_ID, Payment_Type_Name, CC_Type, CC_Approval_Code, CC_Amount, PO_Amount, PO_Number, Discount_Percent, Date_Paid FROM Query_Registration WHERE Course_ID IS NOT NULL AND Paid = 1 AND (PO_Amount IS NOT NULL OR CC_Amount IS NOT NULL) AND Payment_Type_ID IN (4) AND Start_Date > '7/16/2004' ORDER BY FName, Start_Date)) ORDER BY MaxDate

The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.
0
Comment
Question by:dba123
5 Comments
 
LVL 18

Accepted Solution

by:
SjoerdVerweij earned 2000 total points
ID: 11680985
SELECT MaxDate = MAX(Start_Date), EndDate = MIN(End_Date) FROM Query_Registration where start_date IN (Select Start_Date FROM Query_Registration WHERE Course_ID IS NOT NULL AND Paid = 1 AND (PO_Amount IS NOT NULL OR CC_Amount IS NOT NULL) AND Payment_Type_ID IN (4) AND Start_Date > '7/16/2004') ORDER BY MaxDate
0
 
LVL 1

Author Comment

by:dba123
ID: 11680992
thanks, yea, I didn't need all those other fields
0
 
LVL 4

Expert Comment

by:BulZeyE
ID: 11680993
I'm not sure what you are trying to do.  Using the IN clause your sql query should only be selecting a single column to compare  the start_date to.  and.... well it is really hard to see what you are actually trying to do without some explaination.
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11681035
Why not just put SELECT TOP 100 Percent ...

That's all it's asking for.
0
 
LVL 1

Author Comment

by:dba123
ID: 11681051
thank you all
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question