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 |
iboumiza
Starting Member
9 Posts |
Posted - 2011-08-15 : 17:51:58
|
Hi,then here is my conditions:1- Table 1 is old and need update and contains clients name2- Table 2 is new and contain table 1 clients name and new names also3- Table 2 will update Table 1 with new clients name only.How do I design the query, please ?Thanks |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-08-15 : 23:53:32
|
INSERT t1 (column list)SELECT t2.col1, t2.col2....FROM t1LEFT JOIN t2On t1.pk = t2.pkWHERE t1.pk IS NULL; |
|
|
iboumiza
Starting Member
9 Posts |
Posted - 2011-08-16 : 00:39:38
|
Hi,the query is not working! it shows me 0 rows to append...PS: the clients name can be the same on both tables but they have different Primary Keys! Maybe the condition should be set differently? |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2011-08-16 : 05:31:29
|
INSERT t1 (column list)SELECT t2.col1, t2.col2....FROM t1LEFT JOIN t2On t2.name = t1.nameWHERE t2.name IS NULL; |
|
|
iboumiza
Starting Member
9 Posts |
Posted - 2011-08-16 : 09:17:44
|
Hi,I designed like this and now it's working:Table 2 will Append Table 1 with new clients name only. INSERT INTO Table1 ( Table1Name ) SELECT Table2.Table2Name FROM Table2 LEFT JOIN Table1 ON Table2.Table2Name = Table1.Table1Name WHERE (((Table1.Table1Name) Is Null)); Thank you for your help! |
|
|
|
|
|