Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Update SQL table using selection from another table

I want to update the values of a SQL table based on the value from another table where the two tables have a common ID.

When I run my script it says it work. But when I check the table that should have been updated value it still has the old/original value.

I based my script on an article from this site (how-do-i-update-from-a-select-in-sql-server) but because SQL is telling be the script ran with no errors and 2 rows where updated I can’t seem to figure out what I did wrong.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

UPDATE    Table A
SET       Table A.StatusID = 2
FROM      Table B INNER JOIN
          Table A ON Table B.ID = Table A.ID
WHERE     (Table B.ApprovalState = 2)

>Solution :

Your query should be write as tis :

UPDATE    A
SET       StatusID = 2
FROM      TableB AS B INNER JOIN
          TableA AS A ON B.ID = A.ID
WHERE     B.ApprovalState = 2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading