SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 update one table using join with another?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

TestEngineer
Starting Member

USA
29 Posts

Posted - 03/13/2006 :  15:26:26  Show Profile  Reply with Quote
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

United Kingdom
735 Posts

Posted - 03/13/2006 :  15:32:04  Show Profile  Reply with Quote
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

USA
29 Posts

Posted - 03/13/2006 :  16:25:19  Show Profile  Reply with Quote
Thanks! That did the trick.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22460 Posts

Posted - 03/14/2006 :  01:28:26  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000