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.
Author |
Topic |
mshsilver
Posting Yak Master
112 Posts |
Posted - 2012-04-25 : 07:14:47
|
Hi, I have a tough query to work out here and I’m not sure how to go about it.I have three tablesWce_contact – parent table - pkey = uniqueidWce_linkto – Link table links wce_contact to wce_history the wce_contact link field is lentityid and sub entity link field is luniqueid Wce_history – sub entity table – pkey = uniqueidA join of the table would like thisSelect * from wce_contact c join wce_linkto l on c.uniqueid = l.lentityid left join wce_history h on l.luniqueid = h.uniqueid Now my task is to update a field in the wce_history table called area and set it = to the field area in the wce_contact table where the history belongs to the entity record. So I need to find all the records in the wce_contact table where area = “South East” and have the query find related history items in wce_history that belong to the entity record and then update the area in the wce_history table to “South East”.I have been trying alsorts but not getting anywhere near because having the linkto table makes it a little more difficult than I am use to.Any advice would be great thanks for looking. |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-04-25 : 07:24:34
|
Did you try this?update hset area=c.areafrom wce_contact c join wce_linkto l on c.uniqueid = l.lentityid join wce_history h on l.luniqueid = h.uniqueidwhere c.area='South East' No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
mshsilver
Posting Yak Master
112 Posts |
Posted - 2012-04-25 : 09:15:05
|
That looks like it has done it! Many thanks i should have worked that one out... Thanks again. |
 |
|
|
|
|