// Simple TSQL cursor
declare @email nvarchar(255)
declare CustList cursor for
SELECT email from STE_EMAILS
OPEN CustList
FETCH NEXT FROM CustList
INTO @email
WHILE @@FETCH_STATUS = 0
BEGIN
if (SELECT count(custid) from leads where (current_customer=1) and (notes1 is not null) and (notes1 like '%' + @email + '%')) > 0
SELECT custid from leads where (current_customer=1) and (notes1 is not null) and (notes1 like '%' + @email + '%')
print '%' + @email + '%'
FETCH NEXT FROM CustList INTO @email
END
CLOSE CustList
DEALLOCATE CustList