/*Export a distribution list for all contacts in the database with an email address and send emails box checked*/
SELECT [CallListID],
[ContactID],
[Completed],
[ActivityID],
C.firstname,
C.surname,
C.AskFor,
c.position,
C.Department,
C.busname,
C.phone1,Ext1,
C.phone2,Ext2,
C.Cell,
C.Adr1,
C.Adr2,
C.adr3,
C.State,
C.Postcode,
C.email,
C.lastBookDate,
C.Sendme_emails,
H.CallListName,
C.MailList,
C.DecMaker,
C.LastContact,
C.CreateDate
FROM [dev_data-11-2-1].[dbo].[tblCallList] L
left outer join tblcontact C on C.ID = L.contactID
left outer join tbllisthead H on H.id = CallListID
where email <> '' and
Sendme_emails = 'Y' and
CallListname = 'Newsletter'