September 2, 2007 at 5:56 am
Hi All,
Can anyone help me?
I want update my table by using a cursor. I have two tables and want to update table A by using data from table B.Both the tables have same columns but I want to update Text2 for TableA with the Text2 of TableB.
TableA.BookID = TableB.BookID
Update
TableA.Text2 Should be TableB.Text2
Is there any other method to do so?
Please let me know.
Thanks
Zia
September 2, 2007 at 6:44 am
I'm not sure why you have data duplicated in two separate tables... that usually constitutes a violation of 3rd Normal Form... but it's your database...
... something like this will do the job (certainly don't need a cursor, either)...
UPDATE ta
SET Text2 = tb.Text2
FROM TableA ta
INNER JOIN TableB tb
ON ta.BookID = tb.BookID
--Jeff Moden
Change is inevitable... Change for the better is not.
September 3, 2007 at 2:55 am
Thanks Jeff,
The reason for the duplicated data in two tables coz by mistake I have updated that column while removing opostify from it.So I restore the specific data from the backup and it was the only data sitting duplicate in my database.I now have dropped the results duplicated data.
Again thank you very much.
Zia
September 3, 2007 at 2:57 am
hi
if the tables have same columns then you should be able to write a single update query.
update TableB set TableB.Text2 = TableA.Text2 FROM TableA where TableA.BookID = TableB.BookID.
"Keep Trying"
September 3, 2007 at 4:27 pm
Looks pretty familiar, huh?
--Jeff Moden
Change is inevitable... Change for the better is not.
September 3, 2007 at 4:29 pm
You're welcome, Zia. And thank you for taking the time to explain your duplicates.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply