SQL UPDATE STATEMENT NOT WORKING?
February 17, 2010 - 5:27 am
UPDATE TABLENAME as a
SET a.NAME = b.NAME2
FROM TABLENAME2 as b
WHERE
a.ID = b.ID2
What’s wrong, it is not working?
I don’t see anything wrong the the statement alone. What is it not doing? Are you getting errors? Just not updating? Is ID2 the correct field name in TABLENAME2? ID2 seems a little odd. So does NAME2.
If the two tables have different names (ID vs ID2, Name vs Name2) you don’t need the ‘as’ clauses. If they do have the same name, don’t put the 2 after it.
That’s all I can think of without more information.
Good luck.
February 17th, 2010 at 11:14 am
I don’t see anything wrong the the statement alone. What is it not doing? Are you getting errors? Just not updating? Is ID2 the correct field name in TABLENAME2? ID2 seems a little odd. So does NAME2.
If the two tables have different names (ID vs ID2, Name vs Name2) you don’t need the ‘as’ clauses. If they do have the same name, don’t put the 2 after it.
That’s all I can think of without more information.
Good luck.
References :
February 17th, 2010 at 11:49 am
This is one of the main reasons you use a relational database to begin with…to minimize redundant data. What’s wrong is that your table structure is not normalized. If the two tables are related by ID, there is no reason to retain the name in both…that just results in you having to try and keep the names synched up.
References :