I'm programming MS SQL client and I have a problem. I need to make a query:
select_A .. from ( select_B .. from ... )xyz
The query select_B is passed from another methods to the method of SQL client. It could be any select including another subqueries, ORDER BY, GROUP BY etc. clauses. When this query contains ORDER BY clause, there's an error in my testing query:
Server: Msg 1033, Level 15, State 1, Line 6
The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.
I don't want to parse string and add TOP in query as the error says. Is any way to make such select without changing of subselect?
The order by clause in the subquery is unnecessary since it will not affect the output. It will also slow down procesing of the query. Perhaps you should just strip any ORDER BY clauses from the subquery before processing?