I have 2 select statements:
SELECT DISTINCT Email
FROM dbo.Customers
WHERE (Email IS NOT NULL)
AND (Email LIKE '%@%')
AND (RIGHT(Email, 4) IN ('.net', '.com', '.org'))
AND (Email NOT LIKE '%@UniformCity.com')
AND (Email NOT LIKE '%@LifeUniform.com')
AND (CHARINDEX('.',Email) <> 1)
AND (RIGHT(RTRIM(Email), 1) <> '.') AND (LEFT(LTRIM(Email), 1) <> '@')
AND (Email not Like '%[`:;_*-,^[^]()+%\/=#-]%' escape '^') order by Email
AND
SELECT replace(replace(
replace(
replace(EmailOptOut,'"','')
, ',held','')
, ',unsub','')
, ',confirm','')
as CleanEmail
FROM [LifeMail].[dbo].[EmailOptOuts]
I only want to select the emails from the Customers table, THAT ARE NOT in the EmailOptOuts table. What’s the best way to achieve this? I thought about using cursors and looping…
I’m going to put these tables into temp tables, but you could combine the queries if you desired.