Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query optimization
Message
From
29/03/2004 15:59:20
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Query optimization
Miscellaneous
Thread ID:
00890584
Message ID:
00890584
Views:
45
The following query finishes in 2 seconds:
SELECT *
FROM Response 
WHERE BatchID=2
AND Response=1 AND Amount>=500
Next query also finishes in about 2 seconds:
SELECT * 
FROM Response 
WHERE BatchID=2 AND Listcode NOT IN (SELECT CASE WHEN nListcode='' THEN oListcode ELSE nListcode END FROM RawData WHERE CampaignID=@CampaignID AND Mailed>0 GROUP BY CASE WHEN nListcode='' THEN oListcode ELSE nListcode END)
However, following combination of the first two WHERE condition takes almost 3 minutes to complete.
SELECT *
FROM Response 
WHERE BatchID=2
AND Response=1 AND Amount>=500
AND Listcode NOT IN (SELECT CASE WHEN nListcode='' THEN oListcode ELSE nListcode END FROM RawData WHERE CampaignID=@CampaignID AND Mailed>0 GROUP BY CASE WHEN nListcode='' THEN oListcode ELSE nListcode END)
Can anyone tell me why and how to optimize this last query? TIA.
It's "my" world. You're just living in it.
Next
Reply
Map
View

Click here to load this message in the networking platform