select distinct ownerId, ownerType, emailFrom, '' cleanFromDomain from tbl_WRK_Emails with (nolock) where emailFrom like '%@%' and ownerId > 0 and ownerType in ( 'BRO', 'MFR' ) select emailDomain from tbl_WRK_EmailDomains with (nolock) where ownerId = 0 and ownerType = '*' select distinct ownerId, ownerType, cleanFromDomain from qmd_spoofingDomains where cleanFromDomain not in ( ) and cleanFromDomain not in ( ) and cleanFromDomain not in ( ) and cleanFromDomain not in ( ) order by ownertype, ownerId, cleanFromDomain -- #ownerType#:#ownerId# -- #cleanFromDomain# insert into tbl_WRK_EmailDomains( ownerType, ownerId, emailDomain ) select ownerType, ownerId, emailDomain from ( values ( '#ownerType#', #ownerId#, '#cleanFromDomain#' ) ) x ( ownerType, ownerId, emailDomain ) where not exists ( select * from tbl_WRK_EmailDomains e where e.ownerType = x.ownerType and e.ownerId = x.ownerId and e.emailDomain = x.emailDomain ) and 1 = 1;
#encodeforHTML( _r.sql )#