Cannot sort a row of size 8458, which is greater than the allowable maximum of 8094.

  • Hi Everybody!

    I am running a Select query which has nearly 25-30 inner joins...

    When I select top 1 from the query, the results are displayed... But when I give the distinct clause and try to run it, It throws the followign error

    Server: Msg 1540, Level 16, State 1, Line 1

    Cannot sort a row of size 8458, which is greater than the allowable maximum of 8094.1

    Any inputs?

    Thanks,

    Radhika

     

     

     

     

  • Have you tried putting the data into a #TempTable and selecting DISTICT from there? 

    (Are there any aggregates in your select statement?) 

     

    I wasn't born stupid - I had to study.

  • The total size of the length of all the fields in the select statement comes to 8458.

    You need to reduce the fields in your select statement.

    If you have implicit field list using asterisk (*) you need to change to explicit field list. If you have explicit field list already, you need to remove fields. Best fields to remove would be long string fields, eg varchar or char being more than say 80 .

    Distinct is trying to do a sort based on all fields in the select list.

    Robert

    * smile - one size fits all *

  • If you need all fields, you could identify the tables that are generating the duplicate results and put these into a subquery, performing the DISTINCT there. Then join the subquery to rest of the tables.

  • Thanks Everyone!!!!!!!!!

    Let me try ur suggestions and get back....

    Regards,

    Radhika

     

     

     

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply