-
October 1st, 2014, 07:43 AM
#1
Updating one table from another via inner join in MSSQL?
I'm trying to update one table from another, using the following SQL:
Code:
UPDATE c
SET c.state_abbr = s.state_abbr
FROM Cities AS c
INNER JOIN States AS s ON s.state_name = c.state_name
When I verify the syntax, it says it's ok, but appends
to the end of the statement. Verifying the syntax again results in an error with the syntax. Hmmm ...
When I attempt to execute the SQL, it says
Code:
The following errors were encountered while parsing the contents of the SQL pane: Column or expression 'state_abbr' cannot be updated.
Is there actually something wrong with my SQL statement? If so, what?
Thanks.
-
October 1st, 2014, 08:45 AM
#2
Re: Updating one table from another via inner join in MSSQL?
Originally Posted by SlowCoder74
I'm trying to update one table from another, using the following SQL:
Code:
UPDATE c
SET c.state_abbr = s.state_abbr
FROM Cities AS c
INNER JOIN States AS s ON s.state_name = c.state_name
When I verify the syntax, it says it's ok, but appends
to the end of the statement. Verifying the syntax again results in an error with the syntax. Hmmm ...
I used your script in SSMS with SQL Server 2008R2 database and it works!
Could you show your tables?
Victor Nijegorodov
-
October 1st, 2014, 09:33 AM
#3
Re: Updating one table from another via inner join in MSSQL?
Originally Posted by VictorN
I used your script in SSMS with SQL Server 2008R2 database and it works!
Could you show your tables?
Interesting ... I took a look at this: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=105943, and pasted my SQL into the New Query window. It worked!
I was previously using the Show SQL Pane button on the toolbar, which was not working. Live and learn.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|