I am trying to run an update statement that changes a field based on flags in two other tables in two different schemas. "IND" and "GRO" are in different schemas than the main_table mt, and different schemas from each other.
This is the code I am trying - but I am getting the invalid identifier (since I have not referred to the schema.table elsewhere I know this code is wrong).
I have tried using schema.table.field, but I get the invalid identifier error as well. I do not have permissions to make a synonym for the schema.table.
What is the correct way to do this or is there a better way to write this?
main_table -> mt.indID
mt.IndID = schema1.ind.indID
mt.IndID = schema2.gro.indID
schema1.ind.indID = schema2.gro.indID
IndId: 12345 across all tables.
mt_original_field = 1 or 0 (depending on previous update)
ind.inv1 = 0,1,2
gro.indID = 01,02,03,04,05,06,07,08
update main_table mt
set mt.original_field = case
when ind.inv1 <> '2' and gro.dc1 not in ('01')
then 1
else mt.original_field
end;
Expected Outcomes:
ind.inv1 | gro.dc1 | Outcome |
---|---|---|
1 | 01 | original_field |
2 | 3 | 1 |
2 | 01 | original_field |
The next query depends on the outcome of this query as to whether or not it needs to run another update from another table, in another schema.