Good way to use table alias in Update statement?

Sql Server

Sql Server Problem Overview


Using SqlServer, and trying to update rows from within the same table. I want to use a table alias for readability. This is the way I am doing it at the moment:

UPDATE ra 
SET ra.ItemValue = rb.ItemValue
FROM dbo.Rates ra, dbo.Rates rb
WHERE ra.ResourceID = rb.ResourceID
AND ra.PriceSched = 't8'
AND rb.PriceSched = 't9'

Are there easier / better ways?

Sql Server Solutions


Solution 1 - Sql Server

UPDATE ra 
   SET ra.ItemValue = rb.ItemValue
  FROM dbo.Rates ra
 INNER JOIN dbo.Rates rb
         ON ra.ResourceID = rb.ResourceID
WHERE ra.PriceSched = 't8'
  AND rb.PriceSched = 't9';

This might help in improving performance.

Solution 2 - Sql Server

Table alias in Update Query in T-SQL( Microsoft SQL) . for MS SQL Server 2008 R2 it's work just fine

UPDATE A_GeneralLedger  set ScheduleId=g.ScheduleId
from A_GeneralLedger l inner join A_AcGroup g on g.ACGroupID=l.AccountGroupID

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrealcalsView Question on Stackoverflow
Solution 1 - Sql Serverfaizan ahmadView Answer on Stackoverflow
Solution 2 - Sql ServerSubhas MalikView Answer on Stackoverflow