2017-03-02 24 views
0
ID Date  Time   Status UserID 

    1 2017-02-23 19:30:00.0000000 1  130 
    2 2017-02-23 20:00:00.0000000 0  130 

上表是#temptable.This在不同intervals.So上執行時,前2行被插入於下表執行插入從1個表中的一行到另一其不是在第一表中的SQL

 Date  Time   Status 
    2017-02-23 19:30:00.0000000 1 
    2017-02-23 20:00:00.0000000 0 

然後執行,將1行添加到#temptable中,如下所示。

 ID Date  Time   Status UserID 

    1 2017-02-23 19:30:00.0000000 1  130 
    2 2017-02-23 20:00:00.0000000 0  130 
    3 2017-02-23 23:30:00.0000000 1  130 

所以我需要從#temptable到下表是不是在下面的表中插入新行

 Date  Time   Status 
    2017-02-23 19:30:00.0000000 1 
    2017-02-23 20:00:00.0000000 0 
+1

嘗試使用「除」 ... https://msdn.microsoft.com/en-us/library/ms188055.aspx – manderson

回答

0

試試這個

insert into belowTable 
select Date,Time,Status from #TempTable 
except 
select Date,Time,Status from belowTable 
相關問題