I want to make a more complex UPDATE query but I can't seem to make it work.
We have 3 tables, tbl_Companies, tbl_Persons and itbl_company_person.
itbl_company_person is an intermediate table, used because the Company can
have more than one person in it (obviously) and the person can sometimes be a
part of more than one companies (but mostly because when a person leaves a
company to join another one, we don't delete the intermediate record, instead
we have a fld_active_relation which becomes TRUE or FALSE accordingly).
In the itbl_company_person table, there is a fld_personal_email, which is the
personal e-mail of the person in the company. Also in the tbl_Companies table
there is a fld_company_e_mail field (the general e-mail of the company, eg
info@company.com). I just added a new field in itbl_company_person, named
fld_preferred_email. I want to fill this table, giving the value of
fld_personal_email where there is one or, if the fld_personal_email is NULL,
I want to give it the value of fld_company_e_mail.
The query I wrote is the following:
UPDATE itbl_company_person
SET itbl_company_person.fld_preferred_email= (SELECT tbl_Companies.
fld_company_e_mail
FROM tbl_Companies
WHERE itbl_company_person.fld_personal_email IS NULL)
WHERE EXISTS (SELECT tbl_Companies.fld_company_e_mail
FROM tbl_Companies
WHERE itbl_company_person.fld_company_id.person_id=tbl_Companies.
fld_company_id)
I tried to execute it in SQL server, but I get the message
"Msg 258, Level 15, State 1, Line 7
Cannot call methods on int."
Does anyone know what I'm doing wrong?
Thanks.
We have 3 tables, tbl_Companies, tbl_Persons and itbl_company_person.
itbl_company_person is an intermediate table, used because the Company can
have more than one person in it (obviously) and the person can sometimes be a
part of more than one companies (but mostly because when a person leaves a
company to join another one, we don't delete the intermediate record, instead
we have a fld_active_relation which becomes TRUE or FALSE accordingly).
In the itbl_company_person table, there is a fld_personal_email, which is the
personal e-mail of the person in the company. Also in the tbl_Companies table
there is a fld_company_e_mail field (the general e-mail of the company, eg
info@company.com). I just added a new field in itbl_company_person, named
fld_preferred_email. I want to fill this table, giving the value of
fld_personal_email where there is one or, if the fld_personal_email is NULL,
I want to give it the value of fld_company_e_mail.
The query I wrote is the following:
UPDATE itbl_company_person
SET itbl_company_person.fld_preferred_email= (SELECT tbl_Companies.
fld_company_e_mail
FROM tbl_Companies
WHERE itbl_company_person.fld_personal_email IS NULL)
WHERE EXISTS (SELECT tbl_Companies.fld_company_e_mail
FROM tbl_Companies
WHERE itbl_company_person.fld_company_id.person_id=tbl_Companies.
fld_company_id)
I tried to execute it in SQL server, but I get the message
"Msg 258, Level 15, State 1, Line 7
Cannot call methods on int."
Does anyone know what I'm doing wrong?
Thanks.