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
 General SQL Server Forums
 New to SQL Server Programming
 Help updating a joined table

Author  Topic 

pwvailla
Starting Member

31 Posts

Posted - 2010-09-21 : 17:43:07
I am new to TSQL. I am trying to update a joined table and set values into the joined table if the values are present in the source table. I am converting some old SQL from a product called ARTEMIS and the OLD syntax is as follows:


(joined table based on order_no field in each table and all fields are similar datatypes)

set in table_A A (source)
use table_B B
set if order_no exists in table_B
B.busunit = A.busunit if A.busunit present
B.custname = A.custname if A.custname present
B.model_code = A.model_code if A.model_code present
etc...

How would you structure something like this using TSQL 2005?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-09-21 : 18:31:17
Something like this?

UPDATE B
SET B.busunit = A.busunit
,B.custname = A.custname
etc.
FROM
table_B B
INNER JOIN
table_A A
ON
B.order_no = A.order_no

Jim


Everyday I learn something that somebody else already knew
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-23 : 12:59:23
duplicate of

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=150381

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

Go to Top of Page
   

- Advertisement -