Thursday, 19 September 2013

Using Not In with a sub query

Using Not In with a sub query

I have the following query:
select *
from Table1 tb1
where ((tb1.Field1 + tb1.Field2 + tb1.Field3) not in
(
select (tb2.Field1 + tb2.Field2 + tb2.Field3)
from Table2 tb2 )
)
The query runs in about 10 seconds on sql server 2000, but on sql server
2005 it runs for hours. The machines are identical and both environments
have the same keys and indexes. Each table has about 350,000 records. The
only thing I can think of is sql2005 doesn't handle the concatenations the
same. I am working on an upgrade to sql2005 (haha, I wish it would be to
2008 or 2012 but that is out of my control). Any Ideas would greatly be
appreciated.
Thanks, Frank

No comments:

Post a Comment