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 |
pnasz
Posting Yak Master
101 Posts |
Posted - 2014-06-26 : 02:00:32
|
I have a table table1ID Date In Out 22 01/01/2014 10:00 11:0022 02/01/2014 10:00 11:0022 03/01/2014 10:00 11:0023 01/01/2014 10:00 11:0023 02/01/2014 10:00 11:0023 03/01/2014 10:00 11:0024 01/01/2014 10:00 11:0024 02/01/2014 10:00 11:0024 03/01/2014 10:00 11:0025 01/01/2014 10:00 11:0025 02/01/2014 10:00 11:0025 03/01/2014 10:00 11:00Table 2ID Date In Out 22 01/01/2014 10:00 11:0022 02/01/2014 10:00 11:0022 03/01/2014 10:00 11:0023 01/01/2014 10:00 11:0023 02/01/2014 10:00 11:0023 03/01/2014 10:00 11:0024 01/01/2014 10:00 11:0024 02/01/2014 10:00 11:0024 03/01/2014 10:00 11:00I want to insert only those record from table 1 to table 2 which is not there in table 2please help |
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2014-06-26 : 02:16:53
|
can you try thisinsert into table2 select id,dateinout from table1 where id not in(select id from table1)Javeed Ahmed |
|
|
pnasz
Posting Yak Master
101 Posts |
Posted - 2014-06-26 : 02:29:24
|
what if the situation is like this if id 25 is already there in table 2 and i want to insert record for id 25 date 04,05,06. No field is unique here.ID Date In Out 22 01/01/2014 10:00 11:0022 02/01/2014 10:00 11:0022 03/01/2014 10:00 11:0023 01/01/2014 10:00 11:0023 02/01/2014 10:00 11:0023 03/01/2014 10:00 11:0024 01/01/2014 10:00 11:0024 02/01/2014 10:00 11:0024 03/01/2014 10:00 11:0025 01/01/2014 10:00 11:0025 02/01/2014 10:00 11:0025 03/01/2014 10:00 11:0025 04/01/2014 10:00 11:0025 05/01/2014 10:00 11:0025 06/01/2014 10:00 11:00Table 2ID Date In Out 22 01/01/2014 10:00 11:0022 02/01/2014 10:00 11:0022 03/01/2014 10:00 11:0023 01/01/2014 10:00 11:0023 02/01/2014 10:00 11:0023 03/01/2014 10:00 11:0024 01/01/2014 10:00 11:0024 02/01/2014 10:00 11:0024 03/01/2014 10:00 11:0025 01/01/2014 10:00 11:0025 02/01/2014 10:00 11:0025 03/01/2014 10:00 11:00 |
|
|
MariusC
Starting Member
16 Posts |
Posted - 2014-06-26 : 03:36:29
|
You can try this with the MERGE query.Hope this will help:http://www.codeproject.com/Articles/37172/Merge-Statement-in-SQL-Server |
|
|
|
|
|