tags:

views:

1345

answers:

5

Hi all; 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?

A: 

I do it the same way.

Is there anything you don't like about the way you are doing it?

Sergio Acosta
+2  A: 

That's the way to do it.

RedWolves
A: 

@Sergio: not really...just was trying to look it up in BOL and thought it'd be a good SO question!

realcals
+1  A: 

I like to use the optional keyword "AS" (FROM dbo.Rates AS ra) for readability.

Robert S.
A: 

UPDATE ra

SET ra.ItemValue = rb.ItemValue

FROM dbo.Rates ra

INNER JOIN dbo.Rates rb

ON ra.ResourceID = rb.ResourceID

WHERE

AND ra.PriceSched = 't8' AND rb.PriceSched = 't9'

This might help in improving performance.