Dennis
11/6/2018 - 1:35 PM

PON SQL - AUDI - Transactioneel - Brochure

Select lead.Email as 'Lead:Email', lead.id as 'Lead:Id',lead.MiddleName as 'Lead:MiddleName', lead.LastName as 'Lead:LastName', lead.Gender__c as 'Lead:Gender__c', 
lead.Interested_In_Vehicle_Model__c as 'Lead:Interested_In_Vehicle_Model__c', lead.Interested_In_Brand__c as 'lead:Interested_In_Brand__c'
FROM [Lead_Salesforce_1] as lead
Left join _sent on _sent.SubscriberKey=lead.id
Left join _job on _sent.jobid=_job.jobid and _job.EmailName = 'AUDI-brochure dynamisch' 
Where (lead.Lead_Sub_Type__c = 'Brochure' AND lead.LeadType__c = 'New Vehicle' AND lead.Interested_In_Brand__c = 'Audi')
AND cast(switchoffset(todatetimeoffset(lead.CreatedDate, '-06:00'), '+02:00') as datetime) > cast(switchoffset(todatetimeoffset(DATEADD(minute,-20,GETDATE()), '-06:00'), '+02:00') as datetime)
AND (cast(_job.PickupTime as datetime) < cast(DATEADD(minute,-20,GETDATE()) as datetime) OR _job.PickupTime is NUll)