February 14, 2013 at 7:33 pm
So I'm creating a temp table (customersbulk) with three columns and bulk inserting from a comma delimited CSV file. The temp table layout is below.
Account (PK, varchar(50), not null)
Email1 (text, null)
Email2 (varchar(50), not null)
I then want to take the Account and JOIN it to Account in the customers table. I then need to take the values from Email1, Email2, and Email3 from customersbulk and update the fields in the customers table.
So the update statement is where I'm running in to problems.
UPDATE customersbulk cb JOIN customers cp
ON cb.Account=cp.Account SET cp.Email1=cb.Email1, cp.Email2=cb.Email2, cp.Email3=cb.Email3
I'm getting an "Incorrect syntax near 'cb'." when trying to run the update statement. I have also tried with full table names and not setting alias's and I still encounter issues.
UPDATE customersbulk JOIN customers
ON customersbulk.Account=customers.Account SET customers.Email1=customersbulk.Email1, customers.Email2=customersbulk.Email2, customers.Email3=customersbulk.Email3
"Incorrect syntax near the keyword 'JOIN'."
I have also tried the below update statement with out success.
UPDATE customers
SET customers.Account = customersbulk.Account
FROM customers
INNERJOIN customersbulk
ON customers.Email1=customersbulkEmail1, customers.Email2=customersbulkEmail2, customers.Email3=customersbulkEmail3
"Incorrect suntax near 'customersbulk'."
As you can see I'm not fully grasping this and could use a hand please. Most of my work is normally simple select statements or single column updates. I'm working on grasping JOIN's, but not very successfully at the moment.
Thank you for any assistance or feed back you can give.
February 14, 2013 at 8:08 pm
UPDATE customers
SET customers.Account = customersbulk.Account
FROM customers
INNERJOIN customersbulk
ON customers.Email1=customersbulkEmail1, customers.Email2=customersbulkEmail2, customers.Email3=customersbulkEmail3
I will give this a go.
Notice the space between INNER and JOIN and also in the ON clause i changed the "," to AND.
Also you werent specifying "." between table and columns.
UPDATE customers
SET customers.Account = customersbulk.Account
FROM customers
INNER JOIN customersbulk
ON customers.Email1=customersbulk.Email1 and customers.Email2=customersbulk.Email2 and customers.Email3=customersbulk.Email3
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply