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
1,466 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 500 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Database - Move Tables from one Database to Another 4 43
SQL QUERY 3 33
Need time in SQL 8 29
Make an array show the subkey and put it in a query 2 20
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

680 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