Solved

Giant SQL Query

Posted on 2006-11-29
3
495 Views
Last Modified: 2008-01-16
Hello,

The powers that be demand a giant report from our database.  Basically, they would like every piece of information we collect delivered in excel via a 60+ column report.

I have just moved our database from a "custom" design to a relational model.  This brought the total number of tables in the DB from 10 to 32.  

While working to re-create this giant report I ran into an error....

Server: Msg 4414, Level 16, State 1, Line 1
Could not allocate ancillary table for view or function resolution. The maximum number of tables in a query (260) was exceeded.

The reason there are so many is because each trait that is collected they want to view the raw number itself, as well as an average from a particular grouping, and the deviation of an individual from that grouping.  The way I was doing this was to create a view grouped by whatever they want it deviated against and then join that view along with the table that holds that individual data to me report query.  After about 52 columns I have run out of tables I can join.  I guess the most straight forward answer would be to write a procedure that will insert the results into a table so I can start again from there.

In addition, they also want to view data no different from the way they used to on this particular report.  While a relational design helped us to collect and determine new things (per their request) they want to view this report as if nothing changed.  This makes for an ugly query.

Looking for some better ideas....  I could post the query I have so far I didn't because of the length and complexity of it, but if it would help I can post it.

Thanks!


-Navicerts
0
Comment
Question by:Navicerts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 18038620
The maximum number of tables that can be referred in a SELECT Transact-SQL statement is 256. This limit is documented under the "Maximum Capacity Specifications" section of the SQL Server Books Online. This limit includes views and the tables that are referenced in the SELECT statement. Also, the limit includes the tables and the views that are referenced by a view that is included in the query. Therefore, if a table or a view is referenced more than one time in the query, each reference to the table or the view (or the tables and views that are referenced in the view) counts against this limit. If u have installed the latest service pack then this will be 260. If u need to use more than 260 tables , then you may have to break up the query so that a lower number of tables or views are referenced in the query.
0
 
LVL 7

Author Comment

by:Navicerts
ID: 18038700
Hmm, So if I got sloppy anywhere and simply referenced a view a second time instead of taking the value from the original (I don't think I did but really this is madness so I could have) I can go back and remove the second reference.  Aside from that I can go back and make sure I was as efficient as I can be.

I'll do the above and then give in to writing the data to another table.  I'll do the service pack as well but im sure it will surpass 260 as soon as they want to look at the deviation of some number based off a new grouping.

Thanks for there input!
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18038746
I think with your current sp also it is supporting 260 tables and applying the latest sp also wont support beyond the 260  tables. (even sql server 2005 wont support more than this )
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

636 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