Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Giant SQL Query

Posted on 2006-11-29
3
Medium Priority
?
508 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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

877 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