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

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.

Labels: , , , ,