Update using Joins

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'

We can't really tell you is it correct or not.

Why don't you just execute the query and verify the result in the target table. If there are any syntax error you it will display the error message.

By the way "nolock" is one word without space.

You might also want to read this : Bad habits : Putting NOLOCK everywhere

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.