Hi
I want to update two columns using joins.
Can you please verify if below script is correct
Begin transaction
Update a
Set a.calias ='5000', a.unit ='Cons'
From hgrp.master (no lock) as a
Left join hgrp.prj (no lock) as p on p.num = a.num
Left join hgrp.cust6 (no lock) as c6 on c6.alias = a.alias
Left join hgrp.cust12 (no lock) as c12 on c12.alias =a.alias
Where a.stat = 'Dest'
And c2alias = '95000'
You use left joins but in the WHERE statement you use
And c2alias = '95000'
You should mention the table. If it's in the c12 table you can use INNER JOIN, if it's in the "a" table then you don't need the joins at all. It may not change the final result but it would make your query much more understandable for other people.
Thank you for your response.
I will be using the same filter conditions in select query for reporting purposes. So, applied the same condition for better understanding.