Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2003
    Posts
    2

    Unanswered: Problem with subquery

    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?

    Thanks.
    Martin

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    You can't do this directly, but there may be other ways around it.

    What about using a stored procedure or user-defined table function that inserts data from select statement B into a temporary table, and then select statement A queries the temporary table?

    blindman

  3. #3
    Join Date
    Apr 2003
    Location
    SC, USA
    Posts
    51
    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?

  4. #4
    Join Date
    Jun 2003
    Posts
    2
    I know, that ORDER BY clause won't affect the query and I can cut away ORDER BY clause. But I want to avoid parsing of the query, because it could be quite difficult to make it perfect.

  5. #5
    Join Date
    Aug 2003
    Posts
    29
    You can always use TOP 100 PERCENT...
    Joo Marto

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •