Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query optimization
Message
De
30/03/2004 12:11:03
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00890584
Message ID:
00890861
Vues:
19
try this
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 )

-- Mailed IS into RawData ?

-- trasform NOT IN into the LEFT JOIN
SELECT Response.* FROM Response 
LEFT JOIN RawData ON RawData.CampaignID=@CampaignID AND RawData.Mailed>0 
AND Response.Listcode=(CASE WHEN RawData.nListcode='' THEN RawData.oListcode ELSE RawData.nListcode END)
WHERE Response.BatchID=2 AND Response.Response=1 AND Response.Amount>=500 AND RawData.CampaignID IS NULL

-- another is to use a join hint for control the join order and method
-- LOOP | HASH | MERGE | REMOTE

SELECT Response.* FROM Response 
LEFT LOOP  JOIN RawData ON RawData.CampaignID=@CampaignID AND RawData.Mailed>0 
AND Response.Listcode=(CASE WHEN RawData.nListcode='' THEN RawData.oListcode ELSE RawData.nListcode END)
WHERE Response.BatchID=2 AND Response.Response=1 AND Response.Amount>=500 AND RawData.CampaignID IS NULL

-- more specific solutions require the SQL plan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform