I have a local SQL Server table and a remote linked MySQL table.
I need to pull email addresses from the local table to update the remote.
This T-SQL statement works for a single update:
UPDATE openquery(SKYCOMLINK2, 'select tng_id, tng_account, tng_email from user_list where tng_account = 12345 and tng_status = ''A''')
SET tng_email = 'blah@blah.com';
What I want to do is, for every RemoteTable
record with a status of 'A', I want to pull an email address from a local SQL Server table (example for a single record):
select email
from LocalTable
where id = 12345
So in English: for every active record in RemoteTable
(could be multiples) look for a corresponding record in LocalTable
of the same account number (one record per account number) and pull the email address from it to populate the matching records in RemoteTable
. If it makes it easier, the LocalTable
can be the driver as below (in quasi SQL-English):
update RemoteTable
set RemoteTable.email = LocalTable.email
where RemoteTable.accountNum = LocalTable.accountNum
and LocalTable.status = 'a'
and RemoteTable.status = 'a'
How can I do that? Thanks in advance.