I need to update some information which are stored in two tables. To update one of the table, a JOIN with the other table must be done. I was wondering, if I can update both with a single query. Some posts suggested using a trigger. I was hoping there’s another way, since I will have to do it in C#. Also I saw other posts saying it’s possible using something like this:
update pd, pr
set pd.Name = 'Test',
pr.Date = '2012-07-31',
from prDetail pd
left join pr on pd.ID = pr.ID
where pd.Code = '45007'
and pr = '2019'
and pr.Item = '1'
This is not working for me (it’s showing this error: Incorrect syntax near ','). Can this be achieved in some way?
No.
You can only update one table at a time.
Separate your update into two update queries, and if necessary, wrap them in a transaction.