【问题标题】:Insert a row from 1 table to another which are not in first table in sql将一行从一个表插入到另一个不在 sql 中的第一个表中的行
【发布时间】:2017-03-02 14:41:27
【问题描述】:
  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。这是在不同的时间间隔执行的。所以在执行时,前2行插入到下表中

     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

【问题讨论】:

标签: sql sql-server stored-procedures temp-tables


【解决方案1】:

试试这个

insert into belowTable 
select Date,Time,Status from #TempTable 
except
select Date,Time,Status from belowTable 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-25
    • 1970-01-01
    • 2019-01-11
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    相关资源
    最近更新 更多