Internal Query Processor Error: The query processor could not produce a query plan

Internal Query Processor Error: The query processor could not produce a query plan

Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0Share on Reddit0
OK folks, it did happen a few days ago to get this error message:

Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services.

I was trying to execute the following query:

SELECT * 
FROM dbo.tbl1
WHERE 
tbl2ID=(SELECT id FROM dbo.tbl2 WHERE Code=’Code1′)
AND 
tbl3ID=(SELECT id FROM dbo.tbl3 WHERE Code=’Code2′)

As you can see, in the above query I’m using two subqueries for getting some keys for use in my main query. In some cases you might get the aforementioned error message. However, this is not always the case as it depends on many factors and not only on the query itself.

Anyway, in order to resolve the issue I just had to re-write the query. The re-written query is the following:

SELECT  t1.* 
FROM dbo.tbl1 t1, dbo.tbl2 t2, dbo.tbl3 t3
WHERE 
t1.tbl2ID=t2.ID 
AND t1.tbl3ID=t3.ID
AND t2.Code=’Code1′
AND t3.code=’Code2′ 

As you can see, I just removed the subqueries and replaced them with additional joins on my main query. Now my query works like a charm!

*** Before changing your query or doing anything else, first, make sure that your instance of SQL Server has the latest service pack installed.


Recommended eBooks on SQL Server:

Tuning SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Tuning SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Administering SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Administering SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Artemakis Artemiou
Artemakis Artemiou is a Senior SQL Server Architect, Author, Software Developer and a Microsoft Data Platform MVP. He has over 15 years of experience in the IT industry in various roles. Among other, via his initiative SQLEBooks.com, Artemakis authors and publishes eBooks on different topics on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Additionally he is the founder of the SQLArtBits initiative that aims to provide the technical community with simple, yet powerful and high-quality SQL Server tools. Currently, the highlights of these tools are DBA Security Advisor and In-Memory OLTP Simulator. Artemakis's official website can be found at aartemiou.com. Artemakis's blogs can be found at: SQLNetHub.com and TechHowTos.com.