fegdvbna22
Programmer
I have the results of a query (see below) and I want join (left join) the results of this query to another table so that I can I can get all the records that are in the query but not in the join, and then insert the result set into another table.
SELECT UploadDataStaging.CustomerName, UploadDataStaging.Street1, UploadDataStaging.Street2,
UploadDataStaging.City, UploadDataStaging.AccountNumber
FROM (SELECT MAX(AutoID) AS maxid, AccountNumber
FROM UploadDataStaging
GROUP BY AccountNumber) c INNER JOIN
UploadDataStaging ON c.maxid = UploadDataStaging.AutoID
Here is my first attempt, I'm having problems with the syntax (I didn't do the original query, it was done by a colleague). I have commented out the additional lines because I'm not sure of the correct syntax.
--insert into CompanySite([name], Address1, Address2, Town, CustomerAccountNumber
SELECT UploadDataStaging.CustomerName, UploadDataStaging.Street1, UploadDataStaging.Street2,
UploadDataStaging.City, UploadDataStaging.AccountNumber
FROM (SELECT MAX(AutoID) AS maxid, AccountNumber
FROM UploadDataStaging
GROUP BY AccountNumber) c INNER JOIN
UploadDataStaging ON c.maxid = UploadDataStaging.AutoID
--left join on CustomerSite on UploadDataStaging.AccountNumber = CustomerSite.CustomerAccountNumber
--where CustomerSite.CustomerAccountNumber is null
SELECT UploadDataStaging.CustomerName, UploadDataStaging.Street1, UploadDataStaging.Street2,
UploadDataStaging.City, UploadDataStaging.AccountNumber
FROM (SELECT MAX(AutoID) AS maxid, AccountNumber
FROM UploadDataStaging
GROUP BY AccountNumber) c INNER JOIN
UploadDataStaging ON c.maxid = UploadDataStaging.AutoID
Here is my first attempt, I'm having problems with the syntax (I didn't do the original query, it was done by a colleague). I have commented out the additional lines because I'm not sure of the correct syntax.
--insert into CompanySite([name], Address1, Address2, Town, CustomerAccountNumber
SELECT UploadDataStaging.CustomerName, UploadDataStaging.Street1, UploadDataStaging.Street2,
UploadDataStaging.City, UploadDataStaging.AccountNumber
FROM (SELECT MAX(AutoID) AS maxid, AccountNumber
FROM UploadDataStaging
GROUP BY AccountNumber) c INNER JOIN
UploadDataStaging ON c.maxid = UploadDataStaging.AutoID
--left join on CustomerSite on UploadDataStaging.AccountNumber = CustomerSite.CustomerAccountNumber
--where CustomerSite.CustomerAccountNumber is null