Link to home
Start Free TrialLog in
Avatar of dba123
dba123

asked on

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

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.
ASKER CERTIFIED SOLUTION
Avatar of SjoerdVerweij
SjoerdVerweij

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dba123
dba123

ASKER

thanks, yea, I didn't need all those other fields
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.
Why not just put SELECT TOP 100 Percent ...

That's all it's asking for.
Avatar of dba123

ASKER

thank you all