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 |
|
Anterox
Starting Member
4 Posts |
Posted - 2011-09-26 : 09:33:53
|
| Hi, i have two similar tables, table a and table a_history. i need to insert from a to a_history those rows which are no already in a_history. i have to compare two fields, a_hisroty.key1 and a_hisroty.key2. if i only had one key-field, i could use something like that insert into a_history where a_hisroty.key1 not inselect a.key1 from abut when i have 2 key fields how can i compare that? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-09-26 : 11:01:30
|
| insert into a_history select * from a as t1 where not exists(select * from a_hisroty as t2 on t1.key1 t2.key1 and t1.key2 t2.key2)MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-26 : 11:16:03
|
quote: Originally posted by madhivanan insert into a_history select * from a as t1 where not exists(select * from a_hisroty as t2 on t1.key1= t2.key1 and t1.key2= t2.key2)MadhivananFailing to plan is Planning to fail
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-09-26 : 12:13:01
|
MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-26 : 12:18:56
|
quote: Originally posted by madhivanan
MadhivananFailing to plan is Planning to fail
Nice to see you back in action after short interval ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-09-26 : 13:09:22
|
quote: Originally posted by visakh16
quote: Originally posted by madhivanan
MadhivananFailing to plan is Planning to fail
Nice to see you back in action after short interval ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Now-a-days I am busy and do not have enough time to visit here MadhivananFailing to plan is Planning to fail |
 |
|
|
Anterox
Starting Member
4 Posts |
Posted - 2011-09-27 : 03:01:37
|
| Simple as that, thanks. I modified the query a little, replacing 'a_hisroty as t2 ON t1.key1= t2.key1''a_hisroty as t2 WHERE t1.key1= t2.key1' |
 |
|
|
|
|
|