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
 copy data from one table to another

Author  Topic 

junior6202
Starting Member

45 Posts

Posted - 2014-10-16 : 11:35:32
Hi All,

Im a newbie to tsql and I wanted to see if anyone can help me write a query that will grab bin# from table A and if its missing on table B copy it. I tried and update query but it doesn't work and also a select Into and failed too.



Table_A
idx Bin
1 CSR010101A
2 CSR010101B
3 CSR010102A
4 CSR010102B
5 CSR010201A
6 CSR010201B
7 CSR010202A
8 CSR010202B

Table_B

idx Bin
1 CSR010101A
2 CSR010101B
3 Null
4 Null
5 CSR010201A
6 Null
7 CSR010202A
8 NUll

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-16 : 12:02:51
update B
set Bin = a.Bin
from Table_B b
join Table_A a on b.idx = a.idx
where b.Bin is null

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -