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 |
pvong
Yak Posting Veteran
58 Posts |
Posted - 2013-04-17 : 12:08:10
|
I know this is simple but I can not figure it out.Table1----------------Table2ClientID--Date--------ClientID****Date1---------null--------1***********1/2/20132---------null--------3***********4/15/20133---------nullBasically, I just want to update table 1 Date from Table 2 but table 2 does not have all clients.In my example, only client 1 and 3 will have dates while client 2 will stay as Null.Thanks!------------------------------Using VS2010 / Learning in VB.Net / Win2008 R2 / SQL 2008 R2Be kind to the newbies because you were once there. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-04-17 : 12:58:02
|
quote: Originally posted by pvong I know this is simple but I can not figure it out.Table1----------------Table2ClientID--Date--------ClientID****Date1---------null--------1***********1/2/20132---------null--------3***********4/15/20133---------nullBasically, I just want to update table 1 Date from Table 2 but table 2 does not have all clients.In my example, only client 1 and 3 will have dates while client 2 will stay as Null.Thanks!------------------------------Using VS2010 / Learning in VB.Net / Win2008 R2 / SQL 2008 R2Be kind to the newbies because you were once there.
What do you want to do for client 2? Leave it as null? Also, will there be more than one row in Table2 for a given ClientID? If there is which of the dates do you want to apply to Table1?Here is one possible way, which assumes that you want to leave client2 date as null, and that there is only one row in Table2 for a given client id.update t1 set [Date] = t2.[Date]from Table1 t1 inner join Table2 t2 on t1.ClientId = t2.ClientId; |
|
|
|
|
|