March 5, 2010 at 3:55 am
Hello,
I hope this is the right place for this post and that the question that now follows will not be deemed ridiculous or stupid by anyone 🙂
I have 2 tables in SQL Server 2005, one contains a set of Names which are mapped to ID's. I have another table where items are mapped to people via their Names. I would like to replace all the Names in the item table with the ID's of the Names, as they are mapped in the second table. Is there a way to this with a clever SQL statement, or do i need to write a script that will generate individual UPDATE lines for each name?
Thanks,
Alex
March 5, 2010 at 11:56 am
Alter Table [tabletwo]
Add ID int
UPDATE tt
SET tt.id = t.id
From Tabletwo tt
JOIN tableone t
on tt.name = t.name
--make sure there are no null ids in tabletwo before dropping the name column
Alter Table tabletwo
Drop name
Regards,
Toby
March 8, 2010 at 2:41 am
Thank you very much! :kiss:
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply