Good way to use table alias in Update statement?
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?
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.
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