Hopefully this helps somebody. I was getting this error running SQL Server
2008 SP1 64-bit on a Windows Server Enterprise 64-bit with 16GB of RAM.
I was consistently getting the following error while automatedly reloading a database in a development environment:
Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services.
The process just uses a batch file driver (.BAT, DOS) to load scripts based upon a certain load order that I'm dictating (so, DDL scripts first, followed by object - stored procedures, views, functions - definition scripts, followed by loading of lookup tables, followed by loading of other data, etc.). Running the script from within SSMS didn't have much luck either as doing so caused the same internal query processor errors to occur from within SSMS (just as they were when running the script from a .BAT file). However, after some trial and error, I discovered that if I opened the script that creates the stored procedure from within SSMS, run it (the script effectively drops/recreates the SP), and then ran the data load script that all was fine. (Hmm, must be a session setting, right?) More trial and error pointed me to a couple of common themes: 1) I was using a HIERARCHY data type in the stored procedure (the table it was doing the insert for had a column with a HIERARCHY data type), and 2) I didn't have a SET QUOTED_IDENTIFIER ON at the top of the SP. Once I added that to the top of the SP definition, all worked fine.
So, to summarize, this bug appears to occur on SQL Server 2008 SP1 (probably in other versions as well) when the two things mentioned above are occurring. To fix, be sure to always include SET QUOTED_IDENTIFIER ON at the top of your stored procedure definitions when you have a HIERARCHY data type.
So, if your stored procedure definition looks like this...
IF EXISTS (SELECT * FROM sys.objects WHERE object_id OBJECT_ID(N'[dbo].[uspInsert...]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[uspInsert...] GO
CREATE PROCEDURE [dbo].[uspInsert...]( )
Change it to look like this...
SET QUOTED_IDENTIFIER ON;
IF EXISTS (SELECT * FROM sys.objects WHERE object_id OBJECT_ID(N'[dbo].[uspInsert...]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[uspInsert...] GO
CREATE PROCEDURE [dbo].[uspInsert...]( )
Once I took care of that, the auto-load scripts ran without a hitch. Obviously, please note that this may not be the only set of circumstances that cause this error.... but maybe the info contained herein will help you to figure out what your particular situation is. Raul