MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 1st, 2004, 04:38 PM
iRead iRead is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 14 iRead User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I need help structuring an UPDATE statement with multiple joins

Okay I have an application where I need to replace a variable in one data table with the value from another data table. Problem is there are two table in between that relates the records and I can’t figure out how to structure the update statement.

I use a join like the one below to return a record set.

SELECT Table_1.Var_1, Table_1.Var_2, Table_2.Var_3, Table_2.Var_4, Table_2.Var_5, Table_3.Var_6, Table_3.Var_7, Table_3.Var_8, Table_4.Var_9, Table_4.Var_10 FROM Table_1, Table_2, Table_3, Table_4 WHERE Table_1.Var_2 = Table_2.Var_3 AND Table_2.Var_4 = Table_3.Var_6 AND Table_2.Var_5 = Table_3.Var_7 AND Table_3.Var_8 = Table_4.Var_9

I need to then replace Var_1 in Table_1 with Var_10 from Table_4 for all of the records returned by the SELECT statement. The SELECT statement works perfectly. I’ve worked on the update for a while and sadly have made no significant headway. Any suggestions and help will be greatly appreciated.

Thank you!
iRead

Reply With Quote
  #2  
Old April 2nd, 2004, 11:10 AM
sypher sypher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Montreal
Posts: 92 sypher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 5
update table_1
set var_1 =table_4.var_10
FROM Table_1, Table_2, Table_3, Table_4 WHERE Table_1.Var_2 = Table_2.Var_3 AND Table_2.Var_4 = Table_3.Var_6 AND Table_2.Var_5 = Table_3.Var_7 AND Table_3.Var_8 = Table_4.Var_9


Voila!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > I need help structuring an UPDATE statement with multiple joins


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway