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
 update one table using join with another?

Author  Topic 

TestEngineer
Starting Member

29 Posts

Posted - 2006-03-13 : 15:26:26
I have a table with date values that are currently null.

I've created a query that identifies the dates that should go into the date field for the table. I'll call the table "shipping" and the SQL Query, "query".


query has the following fields:
CN int
CSN int
shipdate datetime

shipping has the following fields that are relavent:
CN int
CSN int
shipped_date datetime

I want to update shipping, setting shipping.shipped_date=query.shipdate
where query.cn=shipping.cn and query.csn=shipping.csn

How do I word it to get a proper update using query analyzer?

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2006-03-13 : 15:32:04
UPDATE s
SET s.shipped_date = q.shipdate
FROM shipping AS s
JOIN query AS q
ON s.cn = q.cn
AND s.csn = q.cn
Go to Top of Page

TestEngineer
Starting Member

29 Posts

Posted - 2006-03-13 : 16:25:19
Thanks! That did the trick.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-14 : 01:28:26
Also in SQL Server help file, look for UPDATE (described) under Update

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -