Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query optimization
Message
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Query optimization
Divers
Thread ID:
00890584
Message ID:
00890584
Vues:
44
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.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform