Solved

Giant SQL Query

Posted on 2006-11-29
3
466 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now