Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query optimization
Message
From
30/03/2004 12:11:03
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00890584
Message ID:
00890861
Views:
20
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
Previous
Reply
Map
View

Click here to load this message in the networking platform