I need to use SQL in an automation to compare the data from the "TemporaryDE" with the Data from the "CompareDe". If the CompanyName value from the "TemporaryDE" is not present in the "CompareDe" - to update the "CompareDe" data extension with the CompanyName values and the CustomerID values, and also to update a 3rd data extension calles "AMPscript" with all the values from all the fields from the "TemporaryDE" data extention !!But only for the ones that were not found in the "CompareDe" data extension!!. Since this is my first time using SQL I am pretty sure that my code is wrong.
SELECT s.[CustomerID]
,s.[CompanyName]
FROM [dbo].[TemporaryDE] s
LEFT JOIN [dbo].[CompareDe] d ON
d.[CustomerID] = s.[CustomerID] AND
ISNULL(d.[CompanyName],'') = ISNULL(s.[CompanyName],'') AND
WHERE d.[CustomerID] is NULL
(SELECT s.[CustomerID]
,s.[CompanyName]
,s.[ContactName]
,s.[ContactTitle]
,s.[Address]
,s.[City]
,s.[Region]
,s.[PostalCode]
,s.[FirstName]
,s.[LastName]
,s.[Industry]
,s.[Email]
FROM [dbo].[TemporaryDE] s
LEFT JOIN [dbo].[AMPscript Function 3 - v3] d ON
d.[CustomeID] = s.[CustomerID] AND
d.[CompanyName] = s.[CompanyName] AND
d.[ContactName] = s.[ContactName] AND
d.[ContactTitle] = s.[ContactTitle] AND
d.[Address] = s.[Address] AND
d.[City] = s.[City] AND
d.[Region] = s.[Region] AND
d.[PostalCode] = s.[PostalCode] AND
d.[Industry] = s.[Industry] AND
d.[Email] = s.[Email] AND
ISNULL(d.[CompanyName],'') = ISNULL(s.[CompanyName],'') AND
WHERE d.[CustomerID] is NULL)
WHERE d.[CustomerID] is NULL