Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Aliases in Joined Updates. 1

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
Anyone have an idea why I'm getting Incorrect syntax near 'o' on the following query for SQL2005? Doesn't seem to actually be an aliasing problem; I get a similar error if I just use the table names.

Code:
UPDATE dbo.sub_orders o INNER JOIN dbo.TBL_REGION r ON r.region_name = o.billing_province
SET o.billing_province = r.region_code
 
You need a FROM clause when using multiple table, like this:

Code:
UPDATE o 
SET    o.billing_province = r.region_code
From   dbo.sub_orders As o
       INNER JOIN dbo.TBL_REGION r 
         ON r.region_name = o.billing_province



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
FROM clause in UPDATE is not ANSI standard. MVP Brad Schulz and Hugo Kornelis both written blogs on this topic

Brad Schulz even has a blog 'Dear From Clause' on this exact topic.
-------------------------------------------------------
Dear FROM Clause,

I know that Valentine’s Day is less than a week away, but I felt it was important to write you this letter… I had to put my feelings down on paper. I don’t know quite how to tell you this, but… well… our relationship cannot continue.
-----------------------------------------------------------------


PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top