I am trying to merge two DE (Accounts& Leads) into 1 Master DE. I want to exclude the leads already imported when importing the accounts. This is the SQL:
SELECT T1.Email AS EmailAddress, T1.FirstName AS FirstName, T1.LastName AS LastName, T1.Salesforce_ID_18_Digits_Lead__c AS Lead_ID, T1.Id AS Salesforce_ID FROM Lead_Salesforce T1 WHERE T1.Email IS NOT NULL UNION SELECT T2.PersonEmail AS EmailAddress, T2.FirstName AS FirstName, T2.LastName AS LastName, T2.Salesforce_ID_18_Digits_Accounts__c AS Account_ID, T2.Id AS Salesforce_ID FROM Account_Salesforce T2 WHERE NOT EXISTS ( SELECT Salesforce_ID_18_Digits_Lead__c FROM Lead_Salesforce WHERE T2.Salesforce_ID_18_Digits_Accounts__c = Lead_Salesforce.Salesforce_ID_18_Digits_Lead__c ) AND T2.Salesforce_ID_18_Digits_Accounts__c IS NOT NULL
The error I am getting is:
Converison failed when converting the nvarchar value '0010Y00000GsmrEQAR' to data type bit
The sfid is written from a text field into a text field. I am guessing the where not exist clause returns a bit value.
How can I avoid this problem?