'Update a Column/Cell with Data from Another Table
First, let me preface with; my SQL knowledge is limited, obviously.
I'm trying to draw data from one table and insert it into another table. To be more specific, draw data that only meets specific criteria and place it with data that only meets specific criteria.
table_03.index = foreign index table
table_03.emailAddress = Foreign email address
table_91.emailIndex = the index number of the foreign index
table_91.emailAddress = Where I want the data to go.
What I've tried is:
SET @varEmail = form_91.emailIndex;
SET @newEmail = SELECT form_03.emailAddress FROM form_03 WHERE CONVERT(form_03.index, INT) = CONVERT(form_91.emailIndex, INT);
UPDATE form_91 SET emailAddress = @newEmail WHERE form_91.emailIndex = table_03.index;
...told you it wasn't going to be pretty.
Messing around with this combination, I've been able to produce a "NULL" value in the desired location, but not actually pull the correct email address.
Basically,
if [table_91.emailIndex] == [table_03.index]
then update [table_91.emailAddress]
with [table_03.emailAddress]
... simple right?
All help is certainly appreciated. Thank you ahead of time.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
