Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query 2 tables, update one with data from other

Author  Topic 

mattboy_slim
Yak Posting Veteran

72 Posts

Posted - 2010-03-29 : 13:23:23
I tried to search prior to posting, but I think my lack of results is due to my ignorance of the proper terminology.

I have two tables, tb_menus and tb_restaurants.

Currently, tb_restaurants has one field named "f_itempropertyassignment" while menus has a field that needs to contain the same data called "f_menupropertyassignment".

tb_restaurants has an ID field named f_itemGUID. tb_menus has a field named f_menuassignmentID that relates it to the proper restaurant GUID in f_itemGUID.

Here is a crappy image I made to illustrate, since I often suck at explaning things: {*Image has since been deleted and no longer exists*}


In this case, I could easily just open both tables and manually type the data from the restaurant into the menus table, as there are only about 20 records. However, I feel like learning something today :)

Thanks,
Matt

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-29 : 13:27:23
[code]
UPDATE m
SET m.f_menupropertyassignment = r.f_itempropertyassignment
FROM tb_menus m
JOIN tb_restaurants r
ON r.f_itemGUID = m.f_menuassignmentID
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

mattboy_slim
Yak Posting Veteran

72 Posts

Posted - 2010-03-29 : 14:13:38
Wow, thank you. That works perfectly, and was a far simpler solution than I ever imagined it would be.

- Matt
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-30 : 13:53:15
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-03-30 : 14:04:30
This thread should get an award for the best formatted question. Even use of an illustration. Love it.

There are 10 types of people in the world, those that understand binary, and those that don't.
Go to Top of Page
   

- Advertisement -